Recent detections of high-energy $gamma$-rays from behind-the-limb (BTL) solar flares by the emph{Fermi $gamma$-ray Space Telescope} pose a puzzle and challenge on the particle acceleration and transport mechanisms. In such events, the $gamma$-ray emission region is located away from the BTL flare site by up to tens of degrees in heliogrpahic longitude. It is thus hypothesized that particles are accelerated at the shock driven by the coronal mass ejection (CME) and then travel from the shock downstream back to the front side of the Sun to produce the observed $gamma$-rays. To test this scenario, we performed data-driven, global magnetohydrodynamics simulations of the CME associated with a well-observed BTL flare on 2014 September 1. We found that part of the CME-driven shock develops magnetic connectivity with the $gamma$-ray emission region, facilitating transport of particles back to the Sun. Moreover, the observed increase in $gamma$-ray flux is temporally correlated with (1) the increase of the shock compression ratio and (2) the presence of a quasi-perpendicular shock over the area that is magnetically connected to the $gamma$-ray emitting region, both conditions favoring the diffusive shock acceleration (DSA) of particles. These results support the above hypothesis and can help resolve another puzzle, i.e., long-duration (up to 20 hours) $gamma$-rays flares. We suggest that, in addition to DSA, stochastic acceleration by plasma turbulence may also play a role, especially in the shock downstream region and during the early stage when the shock Alfv{e}n Mach number is small.