I'm confused about how the Tesseract can be in Thor if it was lost 600 years ago, as I know Asgard gave up the red Infinity Stone because they already had another Infinity Stone. What's going on?
The question is imprecise, as you didn't properly tag or indicate the Thor movie you are referencing. However, I believe you are talking about Thor: Ragnarok, where Hela passes by the Tesseract while pillaging Odin's vault.
The Tesseract was brought back by Thor in The Avengers, while also bringing Loki into custody. The Tesseract was thus locked in Odin's vault along with other artefacts. Later on, in Thor: The Dark World, the Asgardians manage to capture the entirety of the Ether; but they decide to entrust The Collector with it. They refuse to keep two Infinity Stones together because of the sheer dangerousness of the Stones.
Thus the Tesseract is kept within Odin's vault until Thor: Ragnarok, where it is stolen by Loki when escaping Asgard. Finally, Thanos comes to take it by force in Avengers: Infinity War.
For the record, the Tesseract does appear in the first Thor movie, in the stinger only. It was recovered by Howard Stark from the bottom of the ocean (where it landed in Captain America: The First Avenger) and given to the top-secret Project PEGASUS to be studied extensively. In Thor's stinger, a brain-washed Erik Selvig participates in Project PEGASUS while under Loki's influence, which directly ties into Avengers' opening sequence.