Using your own means of locomotion on a railway has long been disallowed, because it is seriously dangerous. It was only permitted in the very earliest days of railways in Britain (i.e. the first half of the 19th century), and soon ended for both practical and safety reasons.
L.T.C Rolt, in his book on railway safety Red for Danger, writes:
Hitherto it had been accepted as axiomatic that any highway, whether it was a turnpike, canal or a horse tramway, should be open to all on payment of tolls fixed by statute. Indeed, it was held that for the owners of such highways themselves to act as carriers upon them would be unfair to the private trader and it was for this reason that the canal companies were legally debarred from operating their own fleet of boats. The Liverpool & Manchester Railway [opened 1830] was authorized by Parliament upon a similar basis, but fortunately it was soon recognized that at least the new Company must be exclusively responsible for the provision of motive power. The alternative would have been chaos. Imagination boggles at the thought of a number of 'by-traders', canal fashion, each working their own trains over the same stretch of line.
The greater speeds (and stopping distances) on railways, as well as the inability to "get out of the way" of an oncoming vehicle meant that it was impractical and dangerous to allow anyone to run vehicles on a railway other than the owner (or another company that they made a formal agreement with).
The Railway Regulation Act (1840) made it an offense to trespass upon the railway, with a fine of up to five pounds or two months imprisonment for those found guilty. That allpies whether you have a velocipede with you or not. Subsequent legislation has amended this act over the years (the fine is now up to £1000), but the principle still stands.
You could, in theory, operate a railway velocipede on the UK mainline railway, with the agreement of the owner (Network Rail). They will not realistically allow you to do so without closing the line to all other traffic, as they have a legal responsibility to ensure the railway is operated safely. They may also charge you handsomely for the privilege, and to compensate the others who would normally use the railway. A private or heritage railway may be more willing to close their line for you, but still at a cost.
As a final word, I'd recommend contacting the UK Railway Velocipede Group for more information and guidance. They organise and advertise raillies for their members at heritage railways, where they can operate their velocipedes safely without the danger of a fifty ton locomotive bearing down upon them.