An issue that causes us problems occasionally is making sense of time. The Bible uses different schemes for doing so. For example, in Daniel 9 it divides time by the lengths of different empires. Here in Romans 5, Paul uses another method.
The extent of time that Paul has in mind is from the creation to Jesus and the basis of the division that Paul uses is the law that was given through Moses. Paul mentions two periods connected to it. First, there is the period before the law, which ran from Adam to Moses; second, there was the period of the law, which was from Moses to the coming of Jesus.
Why does Paul say this? I would suggest that he is pointing out that the coming of the law did not deal with the effect of sin, which was death. He shows that there was a big difference between the two periods. Those who lived in the first period from Adam to Moses did not know as much about sin as did those who received the law through Moses. When Paul says that sin was not counted before the law, he does not mean that God did not recognise people as sinners. Paul was fully aware that God had judged the whole world for its sin at the time of the flood. Instead Paul means that humans did not know so much about sin as became known to the Israelites once the law was given (v. 20).
Perhaps we are seeing here another aspect of the failure of Israel to use the God-given law correctly. Instead of using it to show their own sins and the sins of others they opted to make it a means of self-justification, and of imagining that their use of it made them better than the Gentiles. Yet there was one obvious detail that should have highlighted to them that they were using the law in a wrong way, and that detail was that people still died.
The fact that people still died should have revealed the limitations of the law at the same time as they should have realised the benefits of the law, which was to reveal that they were sinful. And God had also told them that one was coming (the Messiah) who would deal with the problem of death. We should be thankful that we know he has come and dealt with it.