I wonder if the lenses that were used on D5300 and D5200 are also compatible with the D7000 and D7100? I am going to buy the body and lenses separately and I want to be sure I am buying the correct lens.
Short answer: Yes. The models all have DX sensors, and since the lenses were bought for a D5300/D5200, they'll likely have an AF motor built in, so you won't have problems mounting them on any other Nikon DX camera, including D7000/D7100.
The D5300 requires lenses that have a built-in motor ( in the lens ) in order to autofocus. Nikon lenses that are suitable will all have the designation "AF-S". Be careful when looking at non-Nikon lenses as they do not use the same designation and in some cases it can be very difficult to tell if a particular lens has a motor or not.
The D7000 series has a motor in the camera body that allows older lenses that do not have a motor to autofocus. So not all lenses that work with the D7000 series will work with the D5300.
Any lens that works on the D5000-series will ( or should ) work on the D7000 series.