It's curious, of course, that the Bible suggests that Joseph suspected (perhaps because he was not a total idiot) that Mary had been with someone else (Matt. 1:18-19), and he decided to divorce her quietly. But Joseph changed his mind after being given information from an angel that the fetus's father was the Holy Ghost (Matt. 1:20), and not, say, Matthias the pizza delivery boy. Joseph was told that the gender of the child would be male and that his name ought to be Jesus. How Joseph knew this messenger was an angel is not explained, nor that he knew who the Holy Ghost was, nor why he thought that the perp being the Holy Ghost excused the whole business, nor that Joesph had any inkling about something being a wee bit strange about a ghost impregnating a girl. And to top it all off, the information was conveyed in a dream, where most people realize they experience a whole bunch of really weird stuff but they shrug it off when they wake.
Joseph didn't shrug it off. So maybe he was a total idiot after all.
But then, in those days, conveying important information through dreams may have been the way it was done. In the very next chapter of Matthew, information is conveyed to the wise men and to Joseph by way of dreams on no fewer than four occasions. They all take the dreams seriously and do or act upon what was conveyed to them in the dreams.
But poor Pontius Pilate, instead of the dream going to him, it went to his wife (Matt. 27:19), and Pontius paid no attention to it. According to standard Christian dogma, however, it's a good thing that the dream went to a silly woman rather than a sensible man, for if Pilate had received the dream himself and acted upon it, then all of humanity would today be damned.