The rules in baseball are that players are under full team control for the first three years—that is the team tenders them a unilateral take-it-or-leave-it one-year contract, or they can non-tender a player and release them as a free agent. The player could ask for more, but the team is under no obligation to negotiate. For the fourth through sixth year, the player and team negotiate salary for the next year, and if they can't agree it goes to binding arbitration. After six years, a player is a free agent and can sign with any team. At any point the team and player can choose to sign a longer-term deal, giving up not only arbitration rights but even delaying free agency if they are so willing.
It's these sorts of extensions or free-agent deals that may include no-trade clauses.
But as mentioned above (albeit with incorrect numbers) any player that has at least 10 years of total service time and 5 years with their current team has an automatic no-trade clause, known as 5 & 10 rights. As baseball has moved towards younger rosters (the thinking being that a call up under full team control is a lot cheaper than a veteran free agent) and less willing to sign longer term deals for free agents, those rights are a lot less common. It's rare for someone to be with a team that many seasons with that much experience.