It's actually an involved legal question. There's been lots and lots of court cases over whether a song just samples a bit from another one, or is similar to another one, or if it's copied.
I remember the one over Blurred Lines (which, unrelatedly, I can't believe flew in 2013) got a lot of media attention.
Wow, the judge is going to laugh the cops out of court.