Section 54 can only be claimed in the case of LTCG from assets other than a residential house property. Whereas, section 54F can be claimed when you have capital gains from a residential property and reinvest the sale proceeds into another residential property.
However, in case of section 54, if the new asset is transferred within 3 years from the date of purchase or construction, then the exemption will be withdrawn.