Is it okay to reference theorem in the secondary source If I don't know where the theorem begins?
Is it okay to reference the theorem in the source that might not be the first paper to prove it?

It’s not only “okay”, but you must cite at least one source you are aware of, and preferably the chronologically earliest one. If you can’t trace the exact provenance of the theorem, then do the next best thing, which is to describe the earliest possible source, and explain that you were unable to determine if that represents the original source or a later source.
Of course, saying this carries with it the assumption that you made reasonable efforts to determine the source, for example by asking your adviser, colleagues, or emailing the author of the paper where you found the theorem if they are still around and easily reachable. If you didn’t make such efforts, then that’s what you should do first of all. But if you did make an effort, then sure, proceeding as I described above is “okay” and is the standard way to proceed.