Will I pass inspection/code if I install walls over carpet in a finished basement for a couple bedrooms?
There is no code or regulation that I know of that putting a piece of carpet between framing and the base (concrete).  However this is really poor workmanship and I could see your local inspector reacting with a raised eyebrow or he could just say he doesn't want it for whatever reason - it is his call.  Also doing something suspect like this would lead me (if I were an inspector) to really really take notice of everything else.

Why would you do it?  Your flooring still has to be retacked and stretched.  What possible benefit are you getting from the floor under the walls?  You could just slice the carpet right in the middle of the wall, roll it back each way and then create your wall.  You could probably get a carpet place to come out and fix the issues for less than $100 - and this could also be a DIY job.