After Saul rescued the city of Jabesh Gilead from the Ammonites, Israel went to Gilgal to celebrate that the Lord had rescued them and to reaffirm Saul’s kingship. There all the people confirmed Saul as king and sacrificed fellowship offerings before the Lord, and Samuel addressed the people.
In his speech, he reminded them of how God had heard the cries of their fathers and had rescued them from Egypt's hand. However, they forgot the Lord their God, therefore He sold them into the hands of their enemies. When it became too much for them to bear, they cried out to God and confessed their sin to Him, so He sent men to deliver them and they dwelt in safety.
In contrast to their their fathers who cried out to God for deliverence, when this generation saw that the Ammonites were coming against them, they said to Samuel, ‘No, but a king shall reign over us,’ even though the Lord their God was their king.
Then Samuel said to them,
“Now therefore, here is the king whom you have chosen and whom you have desired. And take note, the Lord has set a king over you. [14] If you fear the Lord and serve Him and obey His voice, and do not rebel against the commandment of the Lord, then both you and the king who reigns over you will continue following the Lord your God. [15] However, if you do not obey the voice of the Lord, but rebel against the commandment of the Lord, then the hand of the Lord will be against you, as it was against your fathers.
[16] “Now therefore, stand and see this great thing which the Lord will do before your eyes: [17] Is today not the wheat harvest? I will call to the Lord, and He will send thunder and rain, that you may perceive and see that your wickedness is great, which you have done in the sight of the Lord when you asked for a king for yourselves.”
Then Samuel called upon the Lord and He sent rain and thunder, and everyone stood in awe. They all said to Samuel, "Pray to the Lord your God for your servants so that we will not die, for we have added to all our other sins the evil of asking for a king."
Samuel replied, "Do not be afraid. You have done all this evil; yet do not turn away from the Lord, but serve the Lord with all your heart. Do not turn away after useless idols. They can do no good nor can they rescue you because they are useless. For the Lord will not forsake His people, for His great name’s sake, because it has pleased the Lord to make you His people. Moreover, as for me, far be it from me that I should sin against the Lord in ceasing to pray for you; but I will teach you the good and the right way. Only fear the Lord, and serve Him in truth with all your heart; for consider what great things He has done for you. But if you still do wickedly, you shall be swept away, both you and your king.”
Israel's desire for a king was not an insignificant matter in God's sight. It displeased Him because He had set them apart for Himself to be distinguished from the other nations, but they wanted to be like the other nations. God sent rain and thunder as a sign to Israel to show them that asking for a king was wicked because it demonstrated rebellion against Him, because He was their King. When they saw the rain and heard the thunder, they were afraid that God was going to destroy them, and they realized that their asking for a king was evil, so they confessed their sin to Samuel.
Samuel affirmed their assessment that they had done evil and said to them, "You have done all this evil", but then he encouraged them to remain in the Lord: "yet do not turn away from the Lord but serve the Lord with all your heart. Do not turn away after useless idols. They can do no good nor can they rescue you because they are useless".
He is telling them, "yes you have done evil, but if you repent and remain in the Lord, He will not reject you because He was pleased to make you His own." Samuel told them the same thing earlier in verses 14 and 15:
[14] "If you fear the Lord and serve Him and obey His voice, and do not rebel against the commandment of the Lord, then both you and the king who reigns over you will continue following the Lrord your God. [15] However, if you do not obey the voice of the Lord, but rebel against the commandment of the Lord, then the hand of the Lord will be against you, as it was against your fathers."
This is God's requirement for His people. They must obey Him and not rebel against Him. If they do, then He will be against them. But if they repent of their disobedience and rebellion, then His hand will no longer be against them because He will relent of His anger and wrath against them.
Samuel then responded that he would pray for them as they requested, otherwise he would be sinning against God. He considered it his responsibility to teach them "the way that is good and right". This generation evidently did not know the Lord or His ways, so as the "man of God" of Israel, Samuel was going to teach and disciple God's people to obey everything that He commanded them. The first thing: "Fear the Lord", followed by "serve Him faithfully with all your heart", and then, "consider what great things He has done for you".
Samuel concluded his speech with a solemn warning to the people of God:
"Be sure to [do all of the the things listed above], yet if you persist in doing evil, both you and your king will be swept away."
History reveals that God is true to His word, and that He is extremely patient with His people. Israel persisted in doing evil, and many generations later, both they and their kings were swept away by Assyria in the northern kingdom and Babylon in the south.