It's only been a couple of weeks, so this is not a habit yet. It is a fairly reasonable response to a painful experience. Give him time; he needs it.
If he was constipated and had a large, hard stool, he could have sustained a small anal fissure, which can go unnoticed (no blood seen; usually there are a few drops on toilet tissue or undies/diaper.) These hurt until they heal, usually in just a few days, but the memory lingers much, much longer.
Some things you can control, and some you can't. He has to poop; everyone does. But you might consider avoiding things that scare him for a while. Don't put him on the potty until he's had enough soft poops that it no longer scares him to go. After that, reintroduce the chair or toilet (whatever he was successful on before), with praise for trying (praise the process, not the outcome.) If he won't pass stool on the potty chair after a set period of time, just put him back in the diaper. Eventually he'll get back to where he was; you can do what was successful for this the first time around.
Give him high fiber foods (like pumpkin or beans), but also keep him well hydrated; if you give fiber without plenty of fluids, it can make stool harder to pass! Avoid constipating foods (like cheese, etc.) for a while. The lactulose use/dose I'll leave between you and your doctor/nurse.
Mothers have healing powers (or so many kids think); if you think it might help, you can use A&D ointment on his bottom just as a placebo.
If passing stool continues to hurt, then a visit with the child's doctor to make sure there are no medical issues is in order.