When you say one pees outside the box, do you mean that he's going in it, but he's getting pee outside of it, like on the wall? I have a cat that does that at times. He doesn't always put his butt all the way down. To solve this, I use large rubbermaid containers with no lids for litter boxes. They do just fine jumping in and out. I actually stand the lid up behind the box, against the way, to catch anything that might go out, but usually having high sided boxes is enough to keep this from being a problem. This same cat does the thing of scratching the box for several minutes afterwards. We have observed this and tried to figure out why he does it. Sometimes I think that he does it because he does not like the cat litter that gets stuck to his paws. This particular cat is VERY particular about his coat being beautifully groomed, so I just guess he probably does not like nasty pieces of litter stuck to his paws. That's my guess anyway. Also, he does not like a dirty litter box. I have 4 cats and 5 litter boxes, and I scoop them twice a day (or more if someone drops a doozy in there and I'm around to get rid of it). If you use a large box, an entire large 25-35 pound container of litter in the boxes, scoop them twice daily, and hose them out once a month, you will be amazed at how much the cats will want to use the box instead of elsewhere. Cats do not like dirty litter boxes. It took me a long time to realize that most of the litter box problems I have ever had with cats was because either I was not scooping it enough, or the box had gotten old, and even if I had been scooping it, you have to wash those things out about once a month, or they retain the stink, and cats do NOT like a dirty litter box, any more than humans want to use a dirty toilet. If you keep the litter boxes topped off with litter, every few days, and keep it deep enough, the pee won't sink to the bottom and the box won't get as nasty.
How many litter boxes do you have? You need one box per cat and then one. We have also had issues before with one cat bothering the other one while they were trying to use the box, and that can be a BIG cause of problems. What I do now that I know who is doing this, I put him up in a closed room in the morning to eat his food (also because he will eat his and then finish everyone elses), and then he has time in there to use the litter box in that particular room, and everyone else has a chance to eat and go to another litter box in peace, without him staring at them or trying to play. It is kind of a pain having more boxes, but not really, because I'd rather have more than to have issues with someone going out of the box. Sometimes the location of the litter box has a lot to do with accidents too. If it is near something that is scary to the cat, they may avoid it. Or if it's not in a private location, they may not want to go. If you have a litter box with a top to it, that is a big no-no for many cats that have litter box issues. For one, it contains the odors inside, and many of them feel trapped and don't want to go inside, especially if there are other cats in the house. My sister had a litter box with a top and she had it right next to the toilet, and when her cat started having problems, I told her, lose the top, more the box, and the cat had no more problems. It just takes one time for the cat to be using the box, someone flushes the toilet and the cat freaks and doesn't want to use it anymore. Or if the box is in the laundry room, washers and dryers can make scary noises to a cat, or an ice maker on a freezer is another one to scare cats, or a radiator. Location is important. That's why having multiple boxes will usually solve the problem many times, if the cat has several locations to choose from. And it always turns out that one particular box gets used way more than another one. Another thing I do, I wipe down the inside of the litter boxes about once a week, or more if they need it. I use some green/non-toxic wipes, or paper towels. If I keep them wiped down, scooped 2x a day, topped off as the level goes down, and monthly take them out and hose them out and I also clean them with vinegar and water, we don't have problems. Doing this has really solved problems for us that we've had over the years.
I use those large containers, and a few times a year, I'll replace them with new ones, since I usually by the ones that cost about $5, and they don't have to be the rubbermaid ones, but the cheap Target or Walmart ones are fine.
If your cat is declawed, that could be an issue for why there are peeing outside the box issues. I have seen it many times. Declawed cats can have pain and stepping on the litter can be like stepping on glass for them. I do have one cat, my oldest cat, who is declawed, and she has had problems in the past. Even though she does not seem like she has pain, she jumps up on things and seems fine, I sometimes wonder if it might be related to the declawing. Many declawed cats end up in shelters because of this problem. If that is the issue, sometimes you can solve it by first using pee pads in the litter box with a little bit of litter in there, so the cat knows that it is for peeing in, and there are other kinds of litter that are better for declawed cats. I have used the Breeze litter box in the past, it has plastic pellets, and it does not stick to their paws, and this seemed to be something my cat liked. I now use feline pine in her litter box, and she prefers that one to the other boxes with regular litter.
I don't think the scratching thing is an issue. I know many cats who do this. Two of my cats also scratch the floor around their food bowl for several minutes after they eat. I think it's just instinct to do this, like maybe they would in the wild, how they might bury their food to cover up the scent? Of all the litter box issues we have ever had, and we have not had too many, but a few, I strongly believe that keeping several around, keeping them spotlessly cleaned and scooped, in a good location (which is why having several is good in case one spot is a problem), and CLEAN being the #1 issue. Oh, and NO top. Back when I just had my first cat, and we had a hooded litter box, and I only scooped it every few days, and even though I cleaned the bottom out, I didn't thoroughly clean the top and as it would get old, she would start to go outside of it. We would throw it out and get a new one, and that would solve the problem. It took us years before we realized that a top was a bad idea. Good for us, but not for the cats. A box with a top is sort of like going in a porto-let, in my opinion.
I'm sure you know that you must thoroughly clean any spot the cat has peed, on the carpet or furniture etc. I know they make natures miracle, which costs a fortune, but I swear by white vinegar and water, and some baking soda. The vinegar smells bad at first, but it will disappear and it does work very well.
Hang in there. I know how stressful this problem can be. Best of luck to finding a solution. I have been there a few times.