I was of the knowledge that most locomotives "pay for themselves" through passenger revenue, but that's not to say that lines don't make efficiencies wherever possible.
Case in point, during school holidays the GCR mostly just had the Jinty in steam, as it's one of the cheapest to run but still gives visitors the steam train they want. An Austerity (68067) has also recently been restored to take the strain off the Jinty and give 2 "cheap" runners for light traffic and midweek running, while the "big boys" are reserved for weekends and main events.
Likewise, I'm aware that a lot of smaller lines like the Battlefield Line which have the capability but not the financial capacity only run steam services when visitor numbers are expected to be greatest and at pre-designated events. They're also more hamstrung by locomotive crew availability and expertise which can lead to a diesel stand-in at short notice.
I think it was the case that a lot of Galas only just break even due to the sheer number and size of locomotives in steam relative to the number of passengers, and of course a number of the trains in use (goods, TPOs, light engine moves) not generating any profit. A bit of crap weather is often enough to turn off visitors and push the event into overall loss.
This is offset by greater profits during "quieter" events and non "enthusiast" events. The most lucrative events tend to be ones where the trains themselves don't matter as much - speaking again from my knowledge of the GCR, the Bonfire Night event and Santa Specials have some of the best loadings while the traction for them doesn't really matter so much (though it didn't stop them using the 9F for the former this year!) I've no doubt that the Austerity will end up playing a part in the Santa Specials to minimise costs, unless it ends up on loan at another railway, where it will probably end up being utilised for the same purpose.
There are also photo charters, carriage hire groups and dining services which are more lucrative (especially the latter), and a lot of these "profit drivers" offset any financial risk gala events may incur. For charters, the photographers essentially pay to put the loco they want into steam, and any additional profits are ploughed back into the railway to help fund galas. For dining services, and evening services in particular, any steam locomotive will do, and more economic choices are often used (although I have often questioned why freight locomotives with their comparably rough ride often get the nod - the appearance of a "Super D" on the service a few years back led to a number of soups in laps!)
Galas are very important as they attract both enthusiasts and the general public, with a "wow" factor that gets them to come back during times that are paradoxically quieter and yet more valuable overall to the railway's income. That sort of draw helps make up for the financial risk involved with them.
All of this considered, it still doesn't mean the railway will turn a profit - many still rely on membership subscriptions and grants to get their accounts over the line and into the black, which returns me to the original point - that railways have to make efficiencies, like any other industry, as costs continue to rise, but ensure that their customer base is maintained and where possible grows.
I can't fully comment on mainline running, as I don't profess to be that familiar with the sector, but it seems a more volatile market - tours are often cancelled if booking are low and there are numerous additional considerations - higher maintenance, paid engine crews, modern monitoring systems, track access charges, water stops and so on.
Overall, it's not cheap to run steam locomotives and it's only becoming more expensive as coal becomes harder and more expensive to source and heavy industry becomes more fragmented, not just in the UK but overseas as well. I guess we should thank our lucky stars that we have such an established heritage movement providing essentially free manpower for most tasks and that places like Meiningen and Darlington still exist.
NB - Yeah, that was yet another long ramble, but I guess it all boils down to the point that there are a lot of complexities involved with running a railway and operators, especially on the "big" lines, are having to start thinking more seriously about the economic costs of "recreating the experience" with steam and being more sensible with balancing the "off the street" punter with the enthusiast who wants big locos and 100% authenticity. If you said 10 years ago that there'd be an Austerity tank joining the GCR's top shed roster, for example, you'd have been laughed out the room!