The Temporal Prime Directive was a fundamental Starfleet principle.
All Starfleet personnel are strictly forbidden from directly interfering with historical events and are required to maintain the timeline and prevent history from being altered. It also restricts people from telling too much about the future, so as not to cause paradoxes or alter the timeline.
The Temporal Prime Directive is directly related to the Prime Directive.
When Captain James T. Kirk, Spock, and Dr. Leonard McCoy were transported from 2267 to 1930 by the Guardian of Forever, Kirk acted to preserve the timeline by allowing Edith Keeler to be killed in a traffic accident, even though he had become involved with her romantically. Although the Temporal Prime Directive was not mentioned by name, his actions preserved the timeline which culminated in the birth of the Federation and Starfleet. (TOS: "The City on the Edge of Forever")
It is unclear exactly when the Temporal Prime Directive came into effect. The first mention of a Temporal Prime Directive was by Captain Jean-Luc Picard, in 2368. (TNG: "A Matter of Time") Picard postulated that the existence of such a directive might be what was preventing a traveler from the future from aiding him to avert the destruction of Penthara IV. It was clear that Picard was unaware of any formal Starfleet equivalent to a Temporal Prime Directive at this date. Captain Kathryn Janeway seemed to be aware of the directive's existence in 2371, long before the temporal incursion by Captain Braxton in the timeship Aeon in 2373, which implies that the Temporal Prime Directive was not only a 29th century regulation. (VOY: "Shattered", "Future's End") Julian Bashir referred to the similar "temporal displacement policy", something taught at Starfleet Academy, in 2024 when he traveled back in time to that year from 2371. (DS9: "Past Tense, Part I") Starfleet Regulation 157, Section 3, Paragraph 18 also seemed to relate directly to time travel. (DS9: "Trials and Tribble-ations")
The events of the Temporal Cold War may suggest that the regulation had been rescinded, at least temporarily, by the 31st century. However, the Federation faction in the Temporal Cold War is dedicated primarily to keeping the timeline intact and preventing the other factions from interfering with it, which would be completely in keeping with the Temporal Prime Directive's intent. On a few occasions a temporal agent, Crewman Daniels, had to tell the crew of the Enterprise NX-01 some things about the future.
This Directive was violated at least twice by USS Voyager crewmembers from alternate futures. First, Commander Chakotay and Ensign Harry Kim from 2390 altered the past by preventing Voyager from crashing on a Class L planet and killing all aboard. (VOY: "Timeless") Later, an Admiral Kathryn Janeway from the year 2404 went back in time and successfully assisted Voyager in returning some sixteen years earlier than it had in her timeline.
Additionally, the Janeway of the 24th century violated the Directive by accepting the aid of her future self. Her future self took the following attitude regarding the Directive - "It's less of a headache if you just ignore it." Her present self tried to avoid getting knowledge of the future, but after learning that it wasn't so good for several of her close crewmembers, she allowed her future self to tell her about it. Thanks to Admiral Janeway's efforts, Voyager returned home a full sixteen years early (and dealt a crippling blow to the Borg Collective in the process), but this was also a serious breach of the Directive. (VOY: "Endgame")