Great question.
A few things to explain first.
Actually, this may be a revelation to many but people was not held accountable for sin until the law entered which was only given to the Hebrew people. They were the ones under it.
For until the law sin was in the world: but sin is not imputed when
there is no law. - Romans 5:13
However, when the law entered it came in with two sides to it. On the one hand, if the Hebrew's kept all the laws they would be greatly blessed. On the flip side, if they didn't then they were cursed.
You can see these blessings and curses in Deuteronomy 28. The Hewbrews had said to God before the law came - we will do all that you say.
Now with that in mind, the question still remains - what about the flood and Sodom and Gomorrah?
Suppose you were to get gangrene in your leg. The normal course of action to take is to remove the infected part to save the whole. It's like that, the people in the OT times could not be born again and delivered from demonic oppression. In Sodom and Gomorrah they were so corrupted and so demonized that there was no way to save them until Christ came. They couldn't have devils cast out of them because no one had the authority to do so. So you could say although these judgements looked harsh, they were in fact an act of mercy on the world as a whole. Had these people been left in the world, it would have been so corrupted that there wouldn't be a virgin left for a savour to be born through.
Similarly, the law had an imperfect but helpful effect of keeping one group of people partially (imperfictly) upright and focused on God. The law had this effect of being like a whip that helped keep them in order. So while the punishment looks extremely harsh, in actual fact if you look at it from this overall perspective that it was to help keep a people morally upright enough for a saviour to be born who would die for the sin of the entire world... it changes your perspective. Because the real nature of God is exactly like Jesus. Many think Jesus and the father are of a different nature, but actually Jesus said if you've seen me you've seen my father also. In another verse it says he is the visible representation of the invisible God.
Now that Jesus has paid the price for all sin, doesn't that just mean I can go and do what I want?
Yes and no. You have free will to do what you want. But, as pointed out by others, there are consequences. You will open yourself up to the devil. You will reap what you sew. e.g. if you have sex with a prostitute, you run the risk of catching a sexually transmitted disease. And causing all sorts of strife in your family. But, if you do fall into sin you have an advocate with the father.
My little children, these things write I unto you, that you sin not.
And if any man sin, we have an advocate with the Father, Jesus Christ
the righteous: And he is the propitiation for our sins: and not for
ours only, but also for the sins of the whole world. - 1 John 2:1-2
No longer is the father judging you, and Jesus is not condemning you.
For the Father judges no man, but has committed all judgement unto the
Son John 5:22
For God sent not his Son into the world to condemn the world; but that
the world through him might be saved.