Scammers of all kinds use this to defraud people. They send a fake check and the victim deposits the check and sees money credited to the account. After the check is deposited but before it is revealed to be fake, the criminal then ask for money back for some reason. Many people who do not know about this flaw in the system will send money and lose it.
Thousands and thousands of people have been harmed by this. The fraud works because the bank is basically lying to you. They say that you have the money, but you do not. The truth is wildly different from how most people assume bank statements work.
Banks do this because they are forced to by law. There is some stupid banking law somewhere that forces banks to credit money to your account when you give them the check. I am sure that banks would do things differently if this law was not in place. They would only credit a check to your account when it actually cleared, and they would then advertise the fact that customers of their bank are much less vulnerable to frauds as a result.
If they did this, then the only disadvantage would be that you would have to wait a little longer for 'your' money when checks were good. But the banks could probably treat different checks differently if they wanted to. The more reliable kinds of checks could be credited instantly, and the kinds scammers use would not be.
I am not sure what the ideal rule would be. Maybe no regulation would be best. Maybe there should be a rule making it illegal for banks to claim you have the money from the check when you do not. The current way of doing things is basically fraud, and it results in a lot of people losing money to con artists.
This kind of thing is why all laws and regulations should be considered guilty until proven innocent. Every law that is passed has the chance for these kinds of side effects. A single oversight or error in the drafting of legislation can create conditions that hurt people for decades.