Jesus told them those who were trying to kill HIm thought they were serving God because they had no understanding or relationship with Him or the Father and therefore could not know the truth and were trying to destroy HIm out of a lack of understanding. Jesus wanted them to know these things so they would remember His warning and remain faithful. He had not mentioned it earlier because He was still with them. The time was now coming that He needed to tell them because all these things would soon happen.
Jesus explained He was going back where He came from, to the Father. He noticed that none of them asked Him where He was going. Perhaps they finally understood, but to me it seems that they might have been worrying about themselves and what was to become of them. I think they grieved about His leaving because they had not yet come to understand all that was happening and why. Later in the chapter, they said they finally understood because Jesus had stopped speaking figuratively.
Jesus compared the pain of His leaving to a woman experiencing child birth. The pain is nearly unbearable, but when the pain has passed and the child is delivered, the joy is beyond compare. They would hurt and experience the pain of His leaving but when He came back the joy of His resurrection would make it all worth it and no one would ever be able to take that joy away.
He would soon be gone (meaning He would be killed and buried), but then in a little while they would see Him again (speaking to His resurrection). The thought that in a little while they would no longer see Him and in a little while longer they would see Him confused them. Jesus knew they were confused and explained they would weep and mourn over His suffering and death and the world would rejoice in His death. In all of this, they would have unbearable sorrow but when they see Him alive and among them again, they would forever rejoice.
Jesus explained it was good that He leave for then they would have the Advocate, the Holy Spirit, with them all day every day. If Jesus was not to leave, the Holy Spirit would not come to them. He had told them this before and the importance of Jesus sending the Holy Spirit warranted repeating.
They could expect the Holy Spirit to come and convict the world of it’s sin. The sin Jesus was talking about was the fact the world refused to believe in Him. The Spirit would present the world with the righteousness of God and the judgement which was to come. They could be assured the judgment would come because the ruler of this world, Satan, had already been judged. The Holy Spirit would also be a guide to them. He would guide them in truth, He would tell them of the future, and He would bring glory to Jesus because He would tell them what Jesus instructed Him to teach. The Holy Spirit would not speak on His own accord but speak what He has been told to speak.
Once all of this came to pass, they would not have to ask Jesus for anything. They were taught they could ask the Father directly in Jesus' name because the Father loved them because of their love and faith in Jesus. This was a new thing for them because they had always asked Jesus for everything. He clearly validated their belief by saying “Yes, I came from the Father into the world, and now I will leave the world and return to the Father."
The disciples now understood because at this point Jesus had stopped speaking figuratively. Here they assured Jesus they truly believed He had come from God. Jesus added, “Do you really believe?” He said that because the time had finally come when Jesus would complete what He was sent to do. Because of the things that would happen to Him, the disciples would scatter with each one going a different way. They would all run leaving Jesus on His own. Jesus told them that even though they would leave Him, He truly would not be alone because the Father is with Him. Maybe He said this so that they would not think any of this was happening apart from the Father, meaning the Father is in control and sees all things.
All of this was told to them so their faith in Jesus would give them peace in the horrible things that were to come. He told them on earth they would experience many trials and sorrows but they should take heart knowing Jesus had overcome the world. No matter how bad the world may appear, none of it was beyond Jesus' victory over the world, sin, and the evil one. They could take heart in Jesus' victorious return to make all things new.