Both of these might be case where contact was initially made prior to the Prime Directive as a Starfleet policy, and so continued contact was "grandfathered" in.
Actually based on the conversation regarding the Federation Starship Horizon in Piece of the Action the Prime Directive went into effect nearly a hundred years ago.
No, dialog says that the prime directive was nonexistent a hundred years prior to the episode, with no mention of when it came into effect.
Spock: Captain, informing these people they're on a ship may be in violation of the Prime Directive of Starfleet Command.
Even through traveling slower than light, the ship in that episdode was interstellar.
"May be" a violation? Spock is perfectly capable of presenting his Captain with definite factual information. Spock's uncertainty could be the result of the prime directive's exact terms being in a state of constant flux.
I'm reminder of the old Epiphany Trek
website, the last of it's seven point take on the Conundrum of the Prime Directive was "These rules are suspended for those that make war on us
Yonada did fire missiles at the Enterprise. A act of war?
1) Life is sacred. Do what you can to preserve life while following the rest of these principles.
2) First, Do no harm. Examine you actions for potential harm, if acting is significantly worse than not acting, do not act.
3) Second, Allow no harm. This calls upon principle one. Life is more important than anything else. If preserving the life of a world will destroy that world's culture, preserve the life. The culture will rebuild. Sentients have been creating cultures for millions of years, and cultures have been dying out for as long. There is nothing sacred about a culture.
4) There are players (warp capable), and non-players (non-warp capable). Leave the non players alone. Yes, this principle is arbitrary. Like any set of rules, a line has to be drawn between one point and another, between the allowed and the unallowed. We choose to place this line at warp travel. Non-players must be left be to develop their own right ways. They do not need to have them delivered on duralloy tablets from the stars. Principles 1 and 3 can over ride this, but remember principle 2.
5) Our way is not the universal way. Don't shove it down anyone throat. This applies even to players. If someone asks us to let them be, and lets us be also, we will follow their wishes. Some sentients might need the protection and comfort of a totalitarian state. Others might thrive only under total anarchy. Do not judge others by our standard of decency, but by whether the culture is working for them. Someone out there may invent a superior social system we all might find better. They will not however if we give them ours.
6) Free will is paramount. If any Individual feels that their native culture is not working for them they may ask Starfleet for asylum, and they should be granted same. Don't be stupid. Those persons clearly criminal by both the standards of their own culture and the standards of ours cannot expect our protection. Any creature enslaved or oppressed can and should expect our help, even unto risk to ourselves.
7) These rules are suspended for those that make war on us. We will not make war on anyone that does not attack us first. If attacked we will seek peaceful resolution, but not beyond the point of reason. Then we will throw our full combined might against those that make war on us. Once the fighting is over we will seek reasons and resolutions.