“To be sure, sin was in the world before the law was given, but sin is not charged against anyone’s account where there is no law.” Romans 5:13
Yes, people sinned even before the law was given. But it was not counted as a sin because there was no law to break. The law, the Ten Commandments, was given as a mirror, a reflection for us to see that we are sinners. For example, if our freeways had no speed limits, you could travel at any speed you like. If you were travelling at 300km/h and a traffic officer stopped you to fine you, you could reject it as there was no law to break. If they added the speed limit of 120km/h and you exceeded that speed, then you are breaking the law! God gave the law to show His people they were not meeting His requirements and standards. God gave the law to reveal His standard of absolute righteousness to convict us of our true guilt before Him so that we would see our need for the Gospel.