My son won’t poop on the potty?

I’m not sure what to do. He’ll do it sometimes, but most of the time he’ll flat out say no, he doesn’t want to and if I try to sit him on it, he yells and screams. He knows he has to poop, he knows when he’s pooping and he knows that he’s not supposed, but yet he still won’t poop on the potty? I’ve tried to just sit him on the toilet and wait and just keep reassuring him that it’s okay and explaining that pooping on the potty is just what everyone has to do, but I’m not even kidding, he will sit there for 10 minutes or longer holding it, making me think he doesn’t have to go. Then I’ll pull his pants up, and he’ll go and poop in his pants and try to hide it. I’ve never gotten onto him about it really, but if I know that he KNEW he had to go, I’ll explain to him again that pooping on the potty is what we have to do and make him help clean himself up. We he does go on the potty, we really really praise him and yay him and all of that, we have a potty chart, he’s gotten rewarded for pooping on it three times. But it’s like as soon as he gets the toy, he’ll stop. It’s not seeming to help. I obviously won’t get him in trouble for it, I don’t think would help at all, it would probably make him hide it more. I just don’t understand why he knows he needs to go on the toilet and he knows when he has to go, but he just won’t sit on the toilet. Please no judgement, I’m a first time mom and this is my first time potty training. I’m trying my best, I don’t need judgment and hate.