ChatGPT can provide correct citations because somewhere deep in its weights it does lossily encode real texts and citations to real texts. That makes real citations in some cases be its most confident guess for what is supposed to come next in the sentence. But when there isn't a real text it is confident about giving a citation about, but it still feels like a citation should be next in the output, it will happily invent realistic looking citations to texts that have never existed and it has never seen in any sources. On the outside, as readers, it's hard to tell when this occurs without getting an outside confirmation. I'm assuming though that to some degree it is itself aware that a linked citation doesn't refer to anything