TL:DR: It was usually for legitimacy, prestige, or political/family reasons.
At the time, samurai and daimyos actually had three (or more) "names". Your Clan/Family name, your Feudal/Position name, and your personal name.
For personal names, you receive them when you become an adult. Often if you were a lower samurai, you would be given a character, often from your lord's own name. It both gave you prestige and tied you to your lord. Likewise daimyos often received a character from higher daimyos or even the Shogun himself. So this name changes whenever you were given (or want to take away) a character.
The Feudal/Position name was whatever the court grants you. This is what you've actually been addressed as. This changes as you rank up. Further complicating the matter is often daimyo were giving themselves (since the court was powerless) titles to places they had no actual control over. If you had no rank you would use your order name here, often given to you at majority and is not your personal name. It's often your birth order in the family (Taro-"first son"-Jiro-"second son", etc).
Finally your clan/family name. This actually gets very complicated, as most samurai trace their family to either the Minamoto or the Taira. So on official documents from the court they were either Minamoto or Taira (or sometimes Fujiwara). Your offshoot clan name, what we usually use when referring to these people now days as their family name, changes based on circumstances, usually formal adoption. But not always.
And just to make things even more complicated, kids received a child name used until they're adult, unless you were a nobody then this would be the only name you have until you were made a samurai.
So let's take a look at Tokugawa Ieyasu.
He was born to the Matsudaira clan, who were officially Minamoto. His child name was Takechiyo.
When he achieved majority, he received a character from his lord at the time, Imagawa Yoshimoto, and received his personal name, and became Matsudaira Jirosanburo Motonobu. Nobu means faith/loyalty/trust. Jirosaburo means second third son. The name itself might have been his father's and/or grandfather's. Ieyasu was the eldest.
Soon he got married and decided to change his name, also got a rank. So he became Matsudaira Kuradonosuke ("page") Motoyasu. Yasu means healthy, probably. By the way he didn't give up Jirosaburo (you don't usually), and it could still be found in documents.
After he signs an alliance with Oda (Taira) Kazusanosuke (Sub-Lord of Kazusa province, way to the east and at the time under Hojo control) Nobunaga, he decided he wanted to get rid of the character given to him from Imagawa Yoshimoto, because the Imagawa was now his enemy, so became Matsudaira Kuradonosuke Ieyasu. ("Ie" means home/house/clan).
Four years later in 1566, he asked formally for the position of Lord of Mikawa from the court. In his request he trace his offshoot of the Minamoto as Lord of Mikawa. However the court answered that no document could be found that this offshoot was actually ever Lord of Mikawa. After consulting a court official and retainer of Oda Owarinokami (Lord of Owari) Nobunaga, they found/forged a document that says that one of his ancestors who styled himself Tokugawa was given the Lord of Mikawa title. So he changed his clan name to receive the title, and became Tokugawa Mikawanokami (Lord of Mikawa) Ieyasu.
On records he was Minamotonoason (Court Noble of the Minamoto Clan) Tokugawa Jirosaburo Ieyasu.
I am going to stop there because my knowledge is not enough to cover his court rank/title promotions and how he would've been addressed with each promotion.
By the way, you're not supposed to call someone by their personal name (Ieyasu) unless as an insult. You're supposed to refer them by their Feudal/Position name. That of course changes as the person ranks up. When Ieyasu first changed his clan to Tokugawa, you would've addressed him as Mikawanokami (Lord of Mikawa). At the end of his life you'd have addressed him as Naifu (his Naidaijin "Inner Minister" Rank, that he got in 1596). Or you can refer to him by his order name Jirosaburo if you're close enough to him, male, and of similar/elder age and rank.
One last note. Daimyos were very particular about how they were addressed and how they addressed others because of the significance of the names.
For example, the Uesugi addressed the late Hojo as Ise, because Ise was their original clan name. Hojo they got after (probably) requesting use of the name from the court. If the Uesugi accepted the name change, they would be implicitly excepting that they were fighting against the legitimate successors of the Kamakura Shogunate. Likewise, the Takeda referred to the Uesugi of Echigo as Nagao. The Nagao clan were Substitute Shugo, then Shugo (Lord/Protector) of Echigo. The clan changed when Nagao Kagetora (more well known as Uesugi Kenshin) was adopted into the Uesugi and made Kanto Kanrei (Deputy of Kanto). To accept the Uesugi name would mean the Takeda recognized the adoption and that they were fighting against the legitimate Deputy of Kanto.
EDIT: Made a mistake! Third son is pronounced Saburo!