I think this grammar is a remnant of classical Japanese, where nominalizer こと was unnecessary and the dictionary form by itself functioned as a noun. You can find this usage today mainly in proverbs:
- 逃げるが勝ち = 逃げることが勝ち
- 聞くは一時の恥、知らぬは一生の恥 = 聞くことは一時の恥、知らないことは一生の恥
- 袖振り合うも他生の縁 = 袖(が)振り合うことも他生の縁(だ)
As you can see, the following particle can be anything. So 食べるに越したことはない is 食べることに越したことはない, and means "There is nothing that is better than eating", or less literally, "Nothing is as good as eating".
X + に + 越す obviously means "to be better than X", "to surpass X". However, in modern Japanese, 越す is not used in this way, because it's a transitive verb. デジタル大辞泉 treats
Xに越したことはない as a special idiomatic usage.
Unfortunately, an online dictionary of old Japanese (学研古語辞典) doesn't explain
Xに越す at all. So I don't know how common
Xに越す was in archaic Japanese. That being said, the particle に is still commonly used for marking something that is compared with the subject. There are expressions such as "～に匹敵する", "～に並ぶ", "～に及ぶ", "～に似る", and so on, all of which are very common today. So I guess に in
Xに越す can be understood along the lines of these expressions.