Have you had him checked at the Vet ? Older cats can have kidney problems and it may require an effort to produce a result.
And don’t be too harsh about him not liking outside anymore, older cats can be terrorised by the neighbour cats and dogs, and can’t really defend themselves. We had a cat who was bitten by a dog in her later years. She was an Inside Cat after that.
You get litter trays with a lid and a wee hatch they go through – stops all the mess
Good advice here.
The cat might be tending to stay in the house as he/she feels threatened when outside, especially when they are doing their business and even more so when getting on a bit.
We had a litter tray with a flap and a lid until we got a cat flap sorted out. It works really well.
Might also be worth a trip to the vet to check there’s not an underlying health issue.