I agree that this could be a bladder infection, but another possibility is that this could be kidney disease especially since the cat is losing weight. Kidney disease happens when a cat is 7 yrs or older.
This is not a problem that'll just go away, but this could get MUCH worse. I wouldn't delay taking your cat to the vet.
He probably has a bladder infection (the peeing) or cystitis and he assosiates the litter box with pain. A cat only acts like this when they are sick, you should get him to a vet ASAP I hope it is nothing more serious as weight loss is not good.
Let us know how he is doing.