Ordinarily, the gargoyle wouldn't be overcome by a random password.
You seem to be thinking of computers when you talk about being shut out after a certain number of incorrect attempts. This isn't how passwords work in the non-digital world. How difficult it is to gain entry after an incorrect password is down to the strictness of the guard, not some arbitrary prearranged number. In some contexts getting the password wrong once would be enough to merit execution. In others the entree could be left to guess for hours if they wished (or the basis that it's their own time their wasting).
The stone gargoyle outside the headmaster's office was on the more relaxed side. This wasn't "dumb" of it. We have no reason to think that people were randomly guessing the password all the time and gaining access. I'd that had been the case then the system would have been reevaluated fairly quickly. Instead, Harry is the only person who gets in on a lucky guess - and, crucially, that's because he had a head start by knowing a previous password.
When he goes to see Dumbledore in his second year he hears McGonagall saying that the password is sherbet lemon. Consequently, in his fourth year, he is able to correctly guess that the password is cockroach cluster by assuming that Dumbledore is opting for a confectionary-based theme.
Harry had walked right past the stone gargoyle guarding the entrance to Dumbledore's office without noticing. He blinked, looked around, realised what he'd done and retraced his steps, stopping in front of it. Then he remembered that he didn't know the password.
"Sherbert lemon?" he tried tentatively.
The gargoyle did not move.
"OK," said Harry, staring at it. "Pear drop. Er - liquorice wand. Fizzing Whizzbee. Drooble's Best Blowing Him. Bertie Bott's Every Flavour Beans...oh no, he doesn't like them, does he?...Oh, just open, can't you?" he said angrily. "I really want to see him, it's urgent!"
The gargoyle remained immovable.
Harry kicked it, achieving nothing but an excruciating pain in his big toe.
"Chocolate Frog!" he yelled angrily, standing on one leg. "Sugar quill! Cockroach cluster!"
The gargoyle sprang to life, and jumped aside. Harry blinked.
"Cockroach cluster?" he said, amazed. "I was only joking..."
(Goblet of Fire, Chapter 29, The Dream).
It's pretty evident that, even though Harry was guessing wildly, he wouldn't have got in if he hadn't have known that there was a sweets-based genre. If he hadn't have known the first password and hadn't guessed that the new password might be related to the first then he wouldn't have got in. Most students wouldn't have been in a position to know former passwords so would be relegated to pure guesswork. Needless to say, it's a million to one that they should stumble across cockroach cluster.
So the gargoyle's strategy was sound. Harry just got lucky.