There is no specific legislation but the principles of the General Food Law Regulation (EC) 178/2002 (together with those embodied in the Food Safety Act 1990, as amended) apply.
Beer is usually dispensed by allowing the nozzle of the pump to enter the beer within the glass (especially when 'topping up' the last bit of a pint). Your 'old' glass will contain bacteria from your mouth, which will be washed into that beer, so the nozzle is immersed in a liquid containing your bacteria. If some of those bacteria adhere to the nozzle, they can then be passed into the next pint pulled (and thus onto another customer).
If a local authority Food Safety Inspector sees a pub employee dispensing a pint into an 'old' glass (particularly if he/she sees the nozzle enter the beer within that glass) the pub will be marked down in its Food Safety rating, with the licensee being advised to improve staff training.