There are a few reasons your cat isn’t peeing in the litter box.
Medical problem: It’s possible your cat can’t make it to the litter box in time. This can be caused by UTIs, inflammatory diseases, kidney diseases, hormonal problems, general aging, and more (source). If your cat is suddenly unable to make it to the litter box, then contact your vet for a health check-up.
Behavior problem: Stress and anxiety can cause a cat to act differently and pee outside its designated spot. If you’ve changed your routine or the environment, they might also “rebel” and pee elsewhere in the house.
They don’t like the litter tray: Some cats don’t like the litter tray. It may be uncomfortable for them to use or too high to climb into. Another issue is that the litter tray is in an inconvenient location. It’s a good idea to have a few throughout the house, so there’s always one accessible. Lastly, if the litter box is dirty, they may not want to pee in there.
Marking territory: Cats, like dogs, also feel the need to mark their territory. To do this, they pee on objects, usually vertical ones.
Repeated spot: If you haven’t cleaned up an old pee spot, then cats will likely return to that spot and pee there again (source). Make sure to clean up after your cat, so they don’t return to the same spot.