The applicable part of UK law is ROGS and the speed limitation basically comes down to this (from ROGS guidance notes on ORR website):
"Most minor, heritage and leisure railways are not required to have a safety certificate
and/or safety authorisation on account of operating at a permitted maximum speed of
40 km/h or less. However these operations, as well as tramways, will still need to have
an SMS which meets the requirements of ROGS. It is not generally envisaged that
exemptions will be granted from this requirement, although there may be exceptions. "
Obtaining a safety certificate, mentioned by other posters upthread, is the bit that gets expensive.
Yes well said I was about to comment and refer to ROGS (The Railway and Other Guided Transport Systems Safety Regulations 2006). This provides the regulatory and safety regime for all railways in the UK and is mandatory and the regulators (ORR etc) can serve a prohibition notice requiring any operator to cease operations if they are in breach (and there are of course instances where this has happened).
If you drill down a bit further then to operate at more than 40kmh/25mph the regulations require that:-
1. There must be some form of automatic train stop system to prevent collisions from SPADs etc (TPWS performs this function on the majority of Network Rail, Tripcocks fulfill the same function on LU)
2. Passenger vehicles must be of a type that has a structural body not a separate underframe (so no Mk1s or earlier types)
3. Passenger vehicles must have some form of door locking system to prevent doors being opened whilst the train is in motion
There are various other requirements but those are the obvious three that most heritage operations would struggle with.
You can apply for a safety certificate with derogations from the regulations (the most obvious being that some Mk1 vehicles are of course registered for use at speeds greater than 25mph on both Network Rail and LU - as were Pacers until recently) but would not get away with all and the derogation would apply very strict limits on the type and scope of use and on maintenance and inspection regimes.
Incidentally (and not necessarily or relevance to this discussion) regulations also impose an upper speed limit of 125mph on the 'Big Railway' which is why although quite a few trains were designed for higher speeds they do not run above that limit. There are further requirements for running above that speed which is why it does not happen outside of HS1.