I guess Product Managers helps defining and executing the build-deployment-improvement for a product. They don't have any authority over the team.
Project Managers usually deals with different projects, helps in getting things done, allocating resources, etc. They have authority over who's in their team. The focus would be ideally on one or more projects at a time. Each of these projects are time bounded and are relatively shorter in duration.
Program Managers are usually strategic role which involves a ton of stakeholder alignment. Program Manager own program/programs which has multiple sub programs which will help in a achieving a specific goal. It's long term. They may or may not have authority, and usually, they will not have authority and the stakeholders will be a ton of oeopabove them.
Software engineers are really good at what they do. But they're horrible at people skills (in fact they may not need it). Hence, there's a need for all the above roles. Startups may not require Project Managers. If SEs start handling the above roles, they will not get time to do their actual work - writing code.
And when organizations grow, these role should be there to make sure that everything moves forward seamlessly.