The easy way is to make it legally free for residents and charge tourists but don’t actually enforce it. Just put up ads in the airport and all over the tourist hotspots, run a few fake stories in the media of tourists being fined etc.
You get your money for nothing and your travel for free
It seems you'd still need tickets, ticket machines, ticket scanners, ticket sellers, people to put more tickets in the machines, fix the ticket machines and scanners, people to pick up the discarded tickets, etc.
Having laws or rules you intentionally don't enforce at all can't be good for society. Why would people conditioned to steal from the state in one way not be expected to eventually steal from them in others as well?
In Europe, a tourist bed tax is collected from commercial establishments that cater to tourists.
Just increase that bed tax by 2-3 eur daily and use those 2-3 eur towards the public transport budget. Then let anyone use public transport for free, locals or not.
You will miss some people who will seek out couchsurfing opportunities at their friend's home, but you will still earn a lot from all the hotels, pensions and legal AirBnBs.
You get your money for nothing and your travel for free