My question is, if spirits - which are lower beings compared to humans - can possess human beings, then why can't human beings possess, say, a dog or any other animal? How do we make sure that we are never afflicted by such demonic influences?
The hierarchy of beings is just for convenience sake.
Kind of like the "food chain". There is no food chain. There is a food web. Humans like to put themselves at the top, but in reality they can be lunch for many many beings "under them". Ultimately the worms and maggots get the last bite.
There are various means of protecting oneself from demonic influences. There are rites performed for that express purpose. Having meditative stamina would help in recognizing it and resisting.
It is traditionally said that practice of Dharma is beneficial as benevolent devas and other such beings offer protection.