There are two issues that need to be addressed in answering this question. They are whether there was a Roman census in Judea during the reign of King Herod, and if not, why Luke associates the birth of Jesus with the census of Quirinius.
Was a Roman census in Judea during the reign of King Herod?
Ian Wilson says, in Jesus: The Evidence, page 47, the problem with Luke is that the first-ever census did take place during Quirinius’ governorship, in 6 CE, the first year that Judea came under direct Roman control. This is the essence of the first issue - while Judea remained nominally independent, under Kings Herod and Archelaus, Rome did not levy direct taxes in Judea and did not even need to know the population or wealth of the kingdom.
In 6 CE, Rome deposed Archelaus because of his incompetence and brought Judea under direct Roman rule. Quirinius was sent as Legate of Syria, with instructions to assess Judea for taxation purposes. We know enough about the career of Quirinius to know that he could not have served in Syria in any capacity from at least 14 BCE to 3 CE. Josephus reports (Josephus, Jewish Antiquities, XVIII, i, 1) Quirinius and his census:
“Quirinius, a Roman senator who had proceeded through all the
magistracies to the consulship and a man who was extremely
distinguished in other respects, arrived in Syria, dispatched by
Caesar [Augustus] to be governor of the nation and to make an
assessment of their property. Coponius, a man of equestrian rank was
sent along with him to rule over the Jews with full authority.
Quirinius also visited Judaea, which had been annexed to Syria, in
order to make an assessment of the property of the Jews and to
liquidate the estate of Archelaus.”
Wilson (ibid) says there is an unavoidable inference that the Luke gospel’s author may have been trying to make it appear that he knew more about Jesus’ birth than he actually did.
Why does Luke associate the birth of Jesus with the census of Quirinius.
Richard Carrier cites Steve Mason ("Josephus and Luke-Acts," Josephus and the New Testament):
Matthew does not mention anything about it in his account of the
nativity, thus one is left to wonder where Luke learned of it ... the answer could be that Luke borrowed the idea from Josephus, and therefore it probably does not come from
any genuine tradition about Jesus. Finally, it is most unlikely that
Josephus got the information from Luke, for Josephus provides much
more detailed, and more correct information (e.g. he knows exactly
when and why the census happened, that the census was only of Judaea,
not the whole world, etc.), such that it is far more likely that Luke
was drawing upon and simplifying Josephus than that Josephus was
expanding on Luke
Raymond E. Brown says in An Introduction to the New Testament, page 23, "The best explanation is that, although Luke likes to set his Christian drama in the context of well-known events from antiquity, sometimes he does so inaccurately."
Wikipedia tells us:
"Most modern scholars explain the disparity as an error on the part of
the author of the Gospel, concluding that he was more
concerned with creating a symbolic narrative than a historical
account, and was either unaware of, or indifferent to, the
chronological difficulty." [My emphasis]
Uta Ranke-Heinemann says in Putting Away Childish Things, page 11, that Luke wants to make the birth of Jesus in Bethlehem plausible by using the story of the census as a reason for the journey. But in page 8, she explains that according to Roman law, the tax declarations had to be made in the town where the taxpayer resided or, in the case of real estate, in the town where the property was. Joseph would not have travelled all the way from Galilee to Bethlehem unless he owned taxable property there, yet he is portrayed by Luke as exceedingly poor. She points out that even in this case, there was no reason for the heavily pregnant Mary to undertake this arduous journey, as women were not included in censuses.
Raymond E. Brown (An Introduction to the New Testament) and Wikipedia point to Luke making a historical error, being unaware of or indifferent to the actual course of events in history. Uta Ranke-Heinemann (Putting Away Childish Things) takes this a step further and says that the author of Luke's Gospel found the census useful in providing a reason for Joseph and Mary to travel to Bethlehem, where Micah seems to suggest the Messiah must be born.