If it is a BMW extended warranty, yes, it stays with the car and should be good. If it is a third party warranty, the person who purchased the warranty usually has to have it transferred to the new owner. You'd have to get a copy of the warranty to get the details but in the case of a third party warranty you would have something like 60 days to formally write to the covering company and make the transfer.
So bottom line is... It depends! Find out the details from your SA but you may be screwed. If the original owner sold the car to Carmax then its likely he/she did not transfer the third party warranty at that point but that is just me speculating.
Edit: And FormulaMMM is correct, you brought the car in while still covered by the original new car warranty. Just because the dealer couldn't get the part until after the warranty expired, that is their fault, not yours. The dealer should honor the new car warranty in this case...
Current: 2011 Space Grey E90 M3, DCT, Comp. Pkg., Conv. Pkg., everything but Cold Weather Pkg!
Gone: 2008 550, Space Grey, Sports Package, Sport Auto Transmission.
Sold: 2004 545i (U.S.), Steptronic, Silver Gray.