Why did the Davidic dynasty need to come from questionable relations?
On the one side of the family, we have the union between Tamar and Yehudah, which, while technically a fulfillment of Yibum, Yehudah thought she was a harlot. From this union came Peretz (Bereishis 38:15-29), the forebear of David HaMelech (Rus 4:18-22).
On the other side of the family, we have Rus, a descendant of Moav. He was born from the union of Lot with his eldest daughter (Bereishis 19:36-37).
Continuing down the line, David himself married Bas Sheva, after seeing her beauty and sending her husband Uriah to the front lines of the war to be killed in battle such that she would be single (Shmuel 2:11:2-27). From this union came Shlomo HaMelech (ibid. 12:24).
David's lineage was called into question by Doeg HaEdomi, until it was confirmed that a female Moavite convert is not prohibited (Yevamos 76b-77a).
David himself was thought to have been born from the union between Yishai and his maidservant, rather than his actual wife (Me'am Loez to Shmuel 1:16:11; cf. here).
Shlomo himself married Ne'amah, a descendant of Ben-Ami, the son of Lot with his other daughter (Bereishis 19:36,38). Ne'amah went on to be the mother of Rechavam (Melachim 1:14:21).
All of these incidents were either technically permitted or at least done for noble causes, yet smack of something illicit. David married a single woman, after her husband was killed as rebelling against the king (Kiddushin 43a), yet was reprimanded for it (Shmuel 2 ch. 12). Yehudah, even if he didn't know it, was fulfilling the mitzvah of Yibum, yet thought that he was being intimate with a harlot. And Lot's daughters are praised for their actions, as they thought that the world had been destroyed and it was up to them to continue the human race, but at the same time, their actions are termed "sins" for Heaven's sake (Horayos 10b-11a). While Rus was allowed to marry into the congregation, it wasn't without controversy. And Davids mother wasn't confirmed to even be permitted to his father until the truth came out that she wasn't a maidservant.
Why must the Davidic dynasty come from such a background? Why couldn't it be a normal family with normal marriages?