It is okay for a 2 year old boy to sleep in a poopy diaper all night as long as he's sleeping just fine and it's not bothering him.
My 2 year old son has slept in a poopy diaper at night before and was just fine.
He pooped in his diaper sometime during the night and I wasn't aware of it until the next morning and he had pooped in the middle of the night because it wasn't fresh poop in the morning.
Ideally it's best to change diapers even on 2 year old boys and especially girls when they poop, even at night to avoid diaper rash and possible urinary tract infections.
Although going a night in a poopy diaper is generally not all that bad, but he could get a diaper rash.
Applying some diaper rash cream before bed is also a good idea to help prevent diaper rash in the event that he does poop at night or when he's in a wet diaper for longer than he normally would be in the day.
It's also okay to let the 2 year old nap in a poopy diaper, if they are gonna wake up soon anyway.
As long as your 2 year old son is not bothered by the poopy diaper you can let him get some sleep but if it's bothering him, then you should change it and he will likely fall back asleep pretty easily.
Some kids may even be able to sleep through a diaper change but not all.