First of all, in this excerpt from his Taittiriya Upanishad Bhashya Adi Shankaracharya ties the prevention of obstacles from the Devas not to the "śaṃ no mitraḥ śaṃ varuṇaḥ" mantra as a whole, but only to the repetition of the word Shanti or peace at the end of the mantra:
The word "peace" is thrice-repeated for the purpose of destroying the threefold obstacles to the acquisition of knowledge, viz., from one's self, from the living beings and from the Devas.
These three sources of problems aren't unique to Adi Shankaracharya, here is what the first verse of Ishwara Krishna's Samkhya Karika, one of the defining texts of the Samkhya school:
duḥkhatrayābhighātāt jijñāsā tadapaghātake hetau |
dṛṣṭe sāpārthā cen naikāntātyaṅtato abhāvāt ||
On account of affliction from threefold misery, inquiry (should be instituted) into the means for its removal. If (it be said that) it is useless because of the (existence of) evident means (then we reply—) no, because of the absence of certainty and finality.
The Dukhatraya or threefold misery refers to Adhyatmika misery or misery caused within yourself, like bodily diseases and mental sadness; Adhibhautika misery or misery caused by other living beings, like threats posed by wild animals and other humans; and Adhidaivika misery or misery caused by supernatural forces, like natural disasters caused by demons and the like.
Now as to whether and why the Devas stop people from attaining Jnana, here is what this chapter of the Brihadaranyaka Upanishad says:
atha yo'nyāṃ devatāmupāste, anyo'sāvanyo'hamasmīti, na sa veda, yathā paśurevam sa devānām |
yathā ha vai bahavaḥ paśavo manuṣyam bhuñjyuḥ, evamekaikaḥ puruṣo devān bhunakti; ekasminneva paśāvādīyamāne'priyam bhavati, kiṃu bahuṣu? tasmādeṣām tanna priyam yadetanmanuṣyāvidyuḥ
Now if a man worships another deity, thinking the deity is one and he another, he does not know. He is like a beast for the Devas. For verily, as many beasts nourish a man, thus does every man nourish the Devas. If only one beast is taken away, it is not pleasant; how much more when many are taken! Therefore it is not pleasant to the Devas that men should know this.
And since I began by quoting one commentary by Adi Shankaracharya, I might as well end by quoting another:
While he, one who is not a knower of Brahman, who worships another god, a god different from himself, approaches him in a subordinate position, offering him praises, salutations, sacrifices, presents, devotion, meditation, etc., thinking, ‘He is one, non-self, different from me, and I am another, qualified for rites, and I must serve him like a debtor’—worships him with such ideas, does not know the truth. He, this ignorant man, has not only the evil of ignorance, but is also like an animal to the gods. As a cow or other animals are utilised through their services such as carrying loads or yielding milk, so is this man of use to every one of the gods and others on account of his many services such as the performance of sacrifices. That is to say, he is therefore engaged to do all kinds of services for them.
The scriptural rites, with or without the accompaniment of meditation, which this ignorant man, for whom the divisions of caste, order of life and so forth exist, and who is bound to those rites, performs, lead to progress beginning with human birth and ending with identity with Hiraṇyagarbha. While his natural. activities, as distinguished from those prescribed by the scriptures, lead to degradation beginning with the human birth itself and ending with identity with stationary objects. That it is so we shall explain in the latter part of this chapter beginning with, ‘There are indeed three worlds’ (I. V. 16), and continuing right up to the end. While the effect of knowledge (meditation) has been briefly shown to be identity with all. The whole of this Upaniṣad is exclusively devoted to showing the distinction between the spheres of knowledge and ignorance. We shall show that this is the import of the whole book.
Since it is so, therefore the gods can thwart as well as help an ignorant man. This is being shown: As in the world many animals such as cows or horses serve a man, their owner and controller, so does each ignorant man, equivalent to many animals, serve the gods. This last word is suggestive of the Manes and others as well. He thinks, ‘This Indra and the other gods are different from me and are my masters. I shall worship them like a servant through praises, salutations, sacrifices, etc., and shall attain as results prosperity and liberation granted by them. Now, in the world, even if one animal of a man possessing many such is taken away, seized by a tiger, for instance, it causes great anguish. Similarly what is there to wonder at if the gods feel mortified when a man, equivalent to many animals, gets rid of the idea that he is their creature, as when a householder is robbed of many animals? Therefore it is not liked by them, these gods—what?— that men should somehow know this truth of the identity of the self and Brahman. So the revered Vyāsa writes in the Anugītā, ‘The world of the gods, O Arjuna, is filled with those who perform rites. And the gods do not like that mortals should surpass them’ (Mbh. XIV. xx. 59). Hence as men try to save animals from being seized by tigers etc., so the gods seek to prevent men from attaining the knowledge of Brahman lest they should cease to be their objects of enjoyment. Those, however, whom they wish to set free, they endow with faith and the like; while the opposite class they visit with lack of faith etc. Therefore a seeker of liberation should be devoted to worshipping the gods, have faith and devotion, be obedient (to the gods) and be alert about the attainment of knowledge or about knowledge itself. The mention of the dislike of the gods is an indirect hint at all this.