Can I buy any Nikon lens to fit the d5100?

I'm looking into getting a Nikon d5100 body and buying the lens I think would best suit me like the Nikon 24-70mm f/2.8G but I'm wondering if it will fit the body of the d5100?

Any Nikkor AF-S lens will not only fit your camera, but will auto-focus as well.
If you want to save money and do not mind manually focusing a lens, the Nikkor AF lenses will also work. The reason a Nikkor AF (auto-focus) lens will not focus on your camera is because it does not have an internal auto-focus motor on the lens and the camera in an effort to reduce the cost of entry level cameras does not have an auto-focus motor either.
All the Nikon cameras that are NOT entry level (under $1,000 with no lens included) have built-in motors and can use both NIkkor AF-S and AF lenses

It will fit and work and be very good quality. You will be be paying a double high price for its ability to cover a full frame field.

Yes, almost.
All lenses with the Nikon F-mount will fit your camera. Some invasive fisheye lenses will break your camera's reflex mirror. Non-AI and AI lenses won't give you the benefit of using the lightmeter. Lenses without an internal motor won't autofocus. The 24-70mm f/2.8 G will fit your camera but it won't autofocus if it doesn't have the AF-S or AF-I spec.

Any FX lens made by or for Nikon will work.
To see how well each performs with a DX body, go to photozone.de. You may discover other lenses that are much better values. In other words, they may be less sharp by about 10%, but cost 1/5 the price. Take a look at Tamron's f/2.8 zooms.