When you are in a loving relationship with God, when you walk with him and you talk with him, when you are in communion with God, then your will is aligned with His and He can do what is best for you and your receive blessings beyond that which is common to man.
When you reject His love and rebel against his ways then you are out of communion with God. You do not follow his will and often do not understand it. This is the process of sin.
When you sin, God because He is Holy, is restrained by His nature (He cannot stop being Holy which means as one sense of the word 'separate'). He cannot be in the presence of sin or it would destroy the sin and the sinner. (I am sure that is not what you would want.) When you sin He is far from you.
God restrains the universe on your behalf. He holds it together and causes it to function in ways that are good for you. He also restrains nature and causes it to function in ways that are good for you. He does that both on a sociological level by doing things that benefit all mankind in general and by doing things that benefit individuals. But when you are far from God, when you rebel (sin), when you do not walk with Him, when you are out of His will, then He is not able to offer you the same blessings. Additionally, he corrects you and punishes you as a method of bringing you near again (though sometimes you receive blessings as a way of bringing you closer). Additionally, some individuals receive the punishment they deserve as a message to others.
When Elisha was walking near a city that was well known for rejecting God a group of delinquents came out to taunt him and throw rocks at him. Elisha called on God to make an example of them and to remove His blessing from them. Prior to that even though they did not walk with God they received a certain amount of favor. After that God removed what little favor they had and the result was that an angry bear came and mauled them ( the bear was just doing what bears do but with bit less restraint). The story stands as a testimony for you and I about the dangers of removing oneself from the protections of God through our rebellion and sin.