Early years you're typically taught good/bad behavior (if at all). You don't necessarily understand it or get it from a good source.
Then we layer in society to help determine morality.
As you get older, you may use reason to arrive at morality independant of your upbringing and/or society.
As we experience reality, draw conclusions from our feelings and actions and their effect on others.
Game theory can help describe how certain "moral" behaviors come into being. Tit for tat with forgiveness in an iterative dilemma, for example.
Regarding political beliefs, there is an interesting article I read recently that basically says you pick your political party, and then you adopt their positions whether you originally agreed with them or not. The party itself drives belief.
This is basically the "my team" description of political involvement. Us against them. This is how you end up, for example, with an American political party who goes from being against Russia, to being pro-Russia, so they claim.
“Right-wing” and “left-wing” are entirely tribal designations and have no unifying philosophy or principle behind them.
heterodoxacademy.org