I have been reading that the spirit goes straight to heaven when someone dies. If
this is true, when do we get judged as to who will go to heaven or be thrown in hell?
I thought we "sleep" when we die and wait until the second coming.
Your question is one of great debate and concern for all Christians today, and I'm sure, my answer will generate responses from both that are in agreement and disagreement. Be that as it may, in my opinion after prayer to God and research of both Scriptures and Theological sources, this is what I believe.
First, 'sleep' as you have mentioned is what happens to the physical body. The body is not aware of anything because it is an empty shell. It was created from dust and to dust it returns;
".......for dust thou art, and unto dust thou shall return" Gen. 3:19
The 'spirit' returns to God;
“Then shall the dust return to the earth as it was; and the spirit shall return unto God who gave it." Ecc. 12:7
This is what it means to be 'absent from the body and present with the Lord';
"We are confident, I say, and willing rather to be absent from the body, and to be present with the Lord." 2Cor. 5:8
Part of the controversy about all of this comes from the different beliefs as to 'when' this occurs. When Jesus was hanging on the cross, the thief next to him came to belief and asked Jesus to remember him. Jesus response was;
"And he said unto him, Verily I say unto thee, Today shalt thou be with me in Paradise." Luke 23:43
Those that die as unbelievers are in the realm of the dead (Hades). Believers in Christ, and those who are baptized by the Holy Spirit are the ones who are 'in Abraham's bosom'. It is believed, that when one dies, there is an immediate initial judgment and we are kept in a kind of intermediate place. So our initial Judgment happens immediately and for those that do not have their names written in the 'book of life' will be cast into hell when Jesus returns as it is told in the book of Revelation.
The resurrection in the book of Revelation or in the 'second coming' as you refer to is the resurrection of the body to our new bodies. This is where it says 'in a twinkling of an eye' we are changed and are 'caught up in the air with Jesus. This is our bodies, changed into the new bodies and reunited with our spirit. To live with him forever. 1 Cor. 15: 51-52