Why were stupid, senseless laws invented?:
Because someone didn't think they were stupid or senseless. And some of the laws we have now actually may not have been stupid when they were passed (for example a law forbidding to have meat, during periods when cows were seriously ill, and there was no other means to warn the people about the dangers of eating that meat). What is stupid is to forget to remove them when they are no longer useful.

The one you mention (about singing in the bath) seems to have some kind of moral background. It seems stupid to us now. And it probably was stupid by the time it was passed, too. But it responded to the moral standards of that time.