I don't know when a noninterference rule first appeared in science fiction. I just located a quotation mentioning such a rule from a 1897 novel.
My post number 46 at: https://www.trekbbs.com/threads/prime-directive-influenced-by-marvel-comics-the-watcher.311653/page-3
lists several pre Star Trek examples.
Mike Scott's answer says that TV Tropes dates it to Olaf Stapledon's The Star Maker, (1937), which is a great classic of science fiction.
But the online science Fiction Encyclopedia is less certain who was first.
In tales involving Forerunners and their relationship to the species they may have Uplifted, something like a Prime Directive may be evoked, usually to justify the secrecy of their role. Though their secret status is finally divulged to a select few, the Arisians in E E Smith's Lensman sequence (see his entry for dates) do not reveal their true selves, nor the Godgame they are playing with the species they have created, so as not to impose a fatal inferiority complex upon their descendants. Not called so as such, the general principle of noninterference also makes an earlier appearance in Olaf Stapledon's Star Maker (1937), in which "pre-utopian" worlds are "left to work out their own destiny. [...] Great care was taken by the Symbiotic race to keep its existence hidden from the primitives, lest they should lose their independence of mind." [DRL]
If a non interference rule was mentioned by Smith in his Lensman series as early as the magazine appearance of Galactic Patrol in Astounding Stories September 1937 to February 1938, and if that was before the publication date in 1937 of The Star Maker, Smith might possibly have been earlier in print with the concept.
The Technovelgy.com article on Prime Directive says:
As far as the concept of the Prime Directive is concerned, the reader may wish to compare this entry to the Noninterference With Other Worlds from In the Deep of Time (1879) by George Parsons Lathrop, Relations with Extraterrestrial Life from Ogre (1944) by Clifford Simak, to the Law of Contact from Orphans of the Void (1952) by Orville Shaara and the Alien Self-Government from Co-Operate or Else (1942) by A.E. van Vogt.
http://technovelgy.com/ct/content.asp?Bnum=2988
“I would have found a way to come,” he said easily, yet with a strange accent; somewhat as though his words were snowflake crystals, cold at first but melting as they fell. “We had not thought it worth while; but you have made so much advance lately that it seemed best to help you. We Kurols move by will-power. It is said many of our people have come to you secretly before. We know a great deal about your life. But until just now it was against the law for our people to visit earth; it lowered them, and always did you harm, and caused wars among you, much against our will and desire. Even now, I fear my coming will make disturbance.”
In the Deep of Time by George Parson Lathrop, 1897.
Here is a link to a question with an answer mentioning a story from 1960 with a "prime directive".
Story about a lone planetary explorer with a robotic assistant
I tis far from the earliest one, but it also predates Star Trek (1966-1969).
http://technovelgy.com/ct/content.asp?Bnum=3477