Certain nationalities are eligible for transit in China without visa aka TWOV. In PEK, you are allowed up to 72 hours as long as your itinerary takes you to a "third country". HKG is treated as a separate country. In this case, you can do LHR-HKG-PEK-LHR or LHR-PEK-HKG-LHR, but not LHR-PEK-HKG-PEK-LHR without a visa.