Coincidence has been used as a defense in copyright infringement suits before, and courts will certainly consider coincidence if the evidence presented supports it. If similarities are substantial, however, a court may legitimately infer that the work was not the result of mere coincidence and rule in favor of the original copyright holder.
In 1962, a group called the Chiffons recorded a song called "He's So Fine". Bright Tunes music sued George Harrison, of The Beatles, for copyright infringement years later, after Harrison recorded his song "My Sweet Lord". Bright Tunes claimed Harrison's song had two musical phrases that were identical to the copyrighted "He's So Fine". It may have been a coincidence, or "subconscious copying", as Harrison at the time claimed, but that did not stop the suit. Expert musicologists had to be brought in, on both sides, to argue whether it could be mere coincidence or outright copyright infringement that produced these identical notes. Harrison lost with his "coincidence" defense, however, and Bright Tones wound up collecting a large damages award.
Courts are not required to consider whether there is an "intent to infringe" or not, when deciding an infringement action. The material "copied" (coincidentally or not) does not have to be lengthy or extensive if it is idiosyncratic enough, either. It really boils down to how similar the similarity is.
If the similar work is substantially similar, it constitutes unlawful appropriation. If the person who "coincidentally" created a similar work had access to the copyrighted work prior to creation of their own, then it can often be viewed as less of a coincidence and more of a conscious (or even unconscious or subconscious) infringement. If, however, evidence can support a "coincidental similarity", then courts will consider that a legitimate defense to an infringement suit.