Both Ramayana and Mahabharata states about Lord Jagannath. Please see the chapter of the book Lord Jagannath By Suryanarayan Das under the chapter stories from the ramayana and mahabharata (page 12).
Mahabharata does so when describing the Ashvamedh Yajna of Indradyumna and the advent of the deities of the Jagannath temple (Jagannatha, Subhadra and Balabdhara). This is described in more detail in Brahma purana.
Ramayana also states that Sita Mata was obtained by King Janaka near the current Gundhicha mandir.
The origin of Lord Jagannath in vedanta is attributed to 10.155.3 of the Rigveda.
Ado yad daruplavate sindhoh pare apurusam,
Tada rabhasva durhano,tena gaccha parastaram
On a sea-shore there exists the wooden image of a deity with name
purusottama(apurusam). By worshipping that wood so indestructible,
attain the supreme place
In Ramayana,
Aradhya Jaganntham Ekshyaku Kula daibatam, Aradhaniyo Manisham Debanam
Basabai Sahah
Lord Rama advised [Hanuman and Vibhishan] to worship Lord Jagannath who
is deity of Ekshaku clan.
See 108.32 Uttara Khanda of Ramayana
O Mighty Monarch of the Rakshasas, do you worship the Divinity of the
House of Ikshvaku, the Guide of the Universe, Shri Jagannath, whom the
Devas themselves with their leaders perpetually adore.
Extensive references in the puranas
Skanda purana, Chapter 1
Lord Nārāyaṇa is refulgent and self-luminous. He is the Supreme
Puruṣa. How does he stay there in a form made of wood?6 Do narrate
it,
A complete section of Skanda purana is devoted to Lord Jagannatha. Consists of several chapters. This is called Puruṣottama-kṣetra-māhātmya
A king who lived in the Kṛta yuga, and a devotee of Viṣṇu. He visited
the Jagannātha temple in Oḍra Deśa once to worship Lord Jagannātha.
The Lord was then hidden in the sand. When the King, disappointed at
this was about to return, determined to fast unto death at Mount Nīla
when a celestial voice cried, "Thou shalt see Him". Afterwards the
King performed a horse sacrifice and built a magnificent Viṣṇu temple.
After building the temple,
When the temple was nearing completion, Indradyumna feared there might
be more obstacles before he could begin worship. Therefore he traveled
to Brahmaloka to request Lord Brahma himself to come and conduct the
opening ceremony. Due to time dilation, time is experienced
differently in higher and lower realms within this universe. When
Indradyumna finally returned with Lord Brahma, many thousands of years
had passed. A new king named Galamadhava reigned over Puri.
The current is take that
The Pandavas tried to cremate the body of Srikrishna with sandal wood
for seven days, but failed. Not even a single hair from the body got
burnt. The same is described in 'Daru Brahma Gita' by Jagannath Das
and 'Indra Nilamani Purana' by Bamadev. This became the wooden piece
worshipped later.
One research paper that discusses the origin and evolution of the worship of Lord Jagannath is Orissa Review, June 2004.
It is accepted by most of the scholars that in the earliest phase
Jagannath was known as Purushottama. "Vishnudharma", an unpublished
Sanskrit manuscript of 3rd century A.D., says that Krishna was known
as Purushottama in the Odra country.
In the last part of Mahabharat, a mysterious connection is made. Sri
Krishna told Arjuna : now that the war is over, hear what I want, I
wish to take rest in Seealee Lata, a distant forest of Creepers. I
know all. There while sleeping. I will be killed by a tribal man of
Kali Yuga." That dense forest was the ancient site of Jagannath Puri,
as stated in Rig Veda.
"Ato Jutta daru Plabate Sindhupara aparuseya." "Ato" means here.
"Jutta" means that. "Daru" means Wood. "Plabate" means floating.
"Sinshupare" means that side of the ocean. "Aparuseya" means not
man-made.
"Some thing will be carved from a log of wood floating on the ocean
here (describing the origin of the murti of Lord Jagannath along the
beach of Puri) that can not be man made." About that dense forest more
details are given in the ancient Sanskrit text of Jagannath Temple,
called Niladri Mahoday in which the origin of the temple and the basic
outline of the puja system are described. It is stated that the great
Niladri Temple of Lord Jagannath was once on a huge blue hill
surrounded by a dense forest. The inhabitants worshipping Lord
Jagannath here were tribal people called Dayitapatis. Even today a
street of the temple community bears their name, Dayitapati Sahi. Lord
Krishna came here and while resting under a tree, the hunter
Jarasabara appeared. He thought the two feet of Sri Krishna to be the
ears of a deer, so soft and red in colour they were. When he realized
he had killed this Krishna with his bow and arrow, he tried to burn
the body. But it was the body of Deva Purusha Himself : it could never
be burnt. So he left it at a place by the sea in Puri called Banki
Muhan. It become a fossil of wood. This marked the beginning of Kali
Yuga.
Though it is established after Dwapar yug at sea shore of Puri as wooden incarnation of Lord Krishna, the origins may be much older as the Rig veda and Ramayana seem to be quoting him.