This is really the same as many other events in Doctor Who—for example, just in series 6, Melody Pond was named after Amy's best friend, who was actually Melody Pond; the Doctor knew he had to send the blue envelopes because he saw the blue envelopes 200 years earlier; etc.
In every case, there are two possible explanations.
The first possibility is that the apparent circle is actually a spiral. In the original timeline, Shakespeare wrote those lines, and the Doctor later read them. Then the Doctor met Shakespeare and gave him the same lines, changing history. Time isn't linear, and history can change, so this isn't a problem at all. If you want to know the ultimately cause of those lines, it's the version of Shakespeare on the original timeline, before the Doctor changed it (which still 'exists' in some sense, because the Doctor can remember it, and possibly even accidentally visit it by 'jumping a time track').
The other possibility is that it really is a circle. This is called an 'ontological paradox': there's no problem with physical causality, but there is a problem with 'informational causality'. If conservation of information is a fundamental property of the universe (like conservation of mass-energy), then this is a true paradox, but scientists disagree on whether there is such a conservation principle. Besides, the Whoniverse is littered with paradoxes, and it seems like as long as they aren't 'too big' they aren't a problem.
In this particular case, there's actually a third, less interesting possibility: the Doctor invented those lines, and he's always known they were his lines whenever he quoted them (but of course they sound more impressive when everyone knows they come from Shakespeare).