How is a variable sweep wing able to change its sweep?
The easiest way to sweep a wing is an oblique flying wing. This is essentially a straight wing with pivoting rudders and engine pylons which flies at an increasing angle of sideslip where a swing wing aircraft would fold its wings back.
Oblique flying wing (picture source)
If you want to know more, I suggest to read this website. Excerpt:
Although the oblique flying wing concept was described by Jones in 1958 and a drawing by G. H. Lee was published in 1962, the concept received little attention until the 1990's when active digital flight control systems became more capable and widespread. The oblique all-wing configuration was studied in detail by researchers at NASA, Stanford University, McDonnell-Douglas, and Boeing in the 1990's as part of a NASA program.
If the wing is attached to a fuselage, only the wing should move. Again, this can be achieved by pivoting a straight wing, as done in the NASA AD-1 research aircraft, or by folding the wings back with a huge hinge at the wing root, as done on swing wing aircraft.
NASA AD-1 in flight (picture source)
The first aircraft with a variable wing sweep was the Messerschmitt P-1101 which was almost completed in 1945 when WW II ended. It was supposed to fly as a fighter-bomber with reduced wing sweep and as a pure fighter with increased wing sweep, and sweep could only be changed on the ground. On the basis of this design Bell built the X-5 research aircraft, the first to change sweep in flight.
P-1101 under construction (picture source)
The mechanics of a swing wing is rather straightforward: All you need is a big hinge connecting the wing spar at the root and a big hydraulic cylinder or spindle drive for adjusting the wing's sweep angle. And a flexible fairing at the wing root. And something to compensate for the shifting aerodynamic center.
Swing wing mechanism of the F-14 (picture source)