I'm meaning to buy a new 3DS, and I'm worried if I insert my Pokemon Black 2 cartridge into the new one all my progress will be lost. I don't want waste my money buying another copy of the game I already have.
DS and 3DS physical cartridges store the save data on the cart itself. Because of this, it will be retained regardless of what console you play it on. (Of course, this can sometimes be false if you are playing on a fake cartridge, which likely isn't the case.)
In short, yes, your save will be retained.