I've done it a couple of times, that I know of, both with church music:
1) Wrote an Alleluia that wound up being WAY too close to the Quincy Jones Alleluia Chorus from "Messiah: A Soulful Celebration." I hadn't heard it for a year or two before I wrote my piece, nor for three years after. When I finally DID...

Scary. I think it's legal though - clearly derivative, but still a different melody after the first three notes (it's mostly the rhythm that's a direct rip). But it was totally subconscious...
2) ...and speaking of totally subconscious derivative rips, I wrote a Palm Sunday processional that
knowingly borrowed (a) the hosanna from a copyrighted Leon Roberts Mass, and (b) the lyric from "All Glory Laud and Honor", which is in the public domain. The intention was to approach Roberts' publisher with my derivative work (never got around tuit), but mean time, my parish and a parish in Georgia are using it for Palm Sunday. We made sure we bought enough copies of the Roberts Mass so there wasn't an economic issue (though there's still the deal with control of intellectual property - adaptations are very common in church circles, but technically require permission).
ANYHOW - it turns out that my verse melody (to which "All Glory..." is sung) was scary close to Steven Schwarz's "God Save the People" melody, which I hadn't heard in like forever. When I finally bought the DVD and watched it, I got REALLY uncomfortable. But again, it's derivative - it's the melody taken down a third (not transposed, but actually down a third in the same key - a straight transposition won't save you, but a melodic shift will). Still, that may be enough to keep me from moving it forward.
I don't mind being derivative - that's how some of my better stuff gets written. My fear is that I'm unwittingly swiping some exact melody. I've got a bluegrass hymn setting for "Come Labor On" that sounds SO stereotypically bluegrass that I keep thinking it must've been done already. So I'm sitting on THAT one, too.
Daf