The way Salmonella gets into flour is through contamination that can occur either in the processing plant or the field where the flour is grown as wheat.
The Salmonella is commonly found in animal feces and when animals poop out in the field where wheat is growing then the salmonella can infect the flour.
Also there could be contamination in the processing plant that processes the wheat into flour as well.
In rare cases humans can spread salmonella from person to person and then if the person is infected with Salmonella or has some animal feces on something such as their shoes then it could spread through the feces on the persons shoes and then get into the flour or other dry goods.
This is why you don't want to eat raw flour or other raw dough because it can potentially contain salmonella.
When you cook the food and flour then the salmonella will be killed off.