I think it would be impossible to say when the image of Mary riding a donkey became ubiquitous, but it is an old theme and it didn't come out of nowhere.
You're correct that the Bible does not depict Mary riding a donkey into Bethlehem, but she does in the Protoevangelium of James, a 2nd-century infancy gospel which was rejected from the Canon.
And there was an order from the Emperor Augustus, that all in Bethlehem of Judæa should be enrolled.
[...] And [Joseph] saddled the ass, and set [Mary] upon it; and his son led it, and Joseph followed.
[...] And they came into the middle of the road, and Mary said to him: Take me down from off the ass, for that which is in me presses to come forth. And he took her down from off the ass, and said to her: Whither shall I lead you, and cover your disgrace?
Though it was rejected from the Canon it was widely influential, particularly in regards to Mariology (the theology, doctrine, and dogma relating to Mary). And, precisely that image - Mary on a donkey with Joseph following and his son leading the donkey - was depicted in mosaics, carvings, and frescoes.
The more common modern image, of Joseph leading the donkey instead of his son, likely emerged from the protestant rejection of the perpetual virginity of Mary, and therefore the idea of Joseph as an old widower with adult sons.
So, it's an idea that's first attested in the 2nd-century, depicted in art since (at least) the 10th-century, and continues to be one of the popular scenes of the overall nativity imagery.
Addendum: I think it is worthwhile to point out, though I don't currently have any sources for these, two other thoughts on the matter.
Firstly, the dramatic similarity in depictions of the Journey to Bethlehem and The Flight to Egypt. I would be willing to wager that the artistic depictions of these two scenes influenced, and were influenced by, each other. Often the only difference between them is the presence of the Christ Child. This seems unlikely to be coincidence, and makes me wonder which appeared first, and if the latter was a (mis)interpretation of the former which began to replicate on its own.
Secondly, the parallel between Mary entering Bethlehem on a donkey, and Jesus' Triumphal Entry into Jerusalem on a donkey seems likely to be purposeful. Artistic depictions often explicitly make references to other, important, parts of the story. Just as the swaddling cloths parallel the death shroud, and the nativity cave parallels the tomb, having Mary enter Bethlehem - the birthplace of King David - bearing the child who would be the "Son of David", on a donkey, could be an explicit parallel to both the prophecy of the messiah entering Jerusalem on a donkey, and Jesus' later Triumphal Entry.