Quasits can't fly, but everything you've said is true of the imp familiar, so I'm assuming that's what you meant.
For starters, familiars do make excellent scouts. That said, invisibility isn't a "No one can ever detect me" card. It simply allows you to hide without needing something to hide behind. Which means that it still requires a stealth check (unless the DM rules otherwise, of course) to go unnoticed. It's not magically silenced, after all.
If the enemy detects it, it can be resummoned with a short ritual right? Well, yes, but unless the creatures in the castle are mindless zombies or something, they might get suspicious that an invisible devil was flying around their castle. Now the guard patrols are increased and on high alert.
Time pressure can also be useful here. Perhaps an ally of the PCs' is to be executed in a few hours. Sure, they can send the imp to scout the castle, but by the time the imp is done it will be too late to mount a rescue.
As for turning into a centipede to crawl through locks, you're the DM. You're well within your rights to rule that the imp can only turn into a bigger (12 inch) centipede, which is too large to fit through most locks (but may be small enough to crawl under some doors).
Finally, and most importantly, keep in mind that this a feature that the player selected at the cost of other features. It's fine to limit it, but be careful not to limit it to the brink of being useless, because the player is likely to get (in my opinion, justifiably) upset. You don't have to let the imp get away with murder, but let him be useful and scout at least some of the enemy positions. It's a matter of feeling out the right balance. Don't be so concerned about your story that you forget to keep the players' fun in mind. It's okay (and generally expected) for the story to change and evolve during play.
They can't fly but can turn into a bat which has the same effect. Are you sure an invisible creature still needs to make a stealth check to not get detected? Then what's the difference between it not being invisible and being invisible. Shouldn't invisibility make you undetectable unless you make like a noise or there is a smell or something? Should it like add some number to it's stealth rolls or?
Yes if it gets caught obviously I make the creatures suspicious and send patrols, increase guards etc. Problem is he can make the quasit disappear in an instant. So if it fails a check or gets detected most of the time it's instantly gone and a lot of guards would realistically go "oh am I just seeing things? Bah". Sure if they are knowledgeable in magic and know what quasits are they will know what's up but... a very small portion of guards are.
I don't want to make it useless of course. I just want to be able to outsmart it at least in some more important story developments. My only goal is to make things interesting and I find that players knowing too much all the time accomplishes exactly the opposite - makes things boring and predictable.
The time pressure is a good idea
