Change the file ending to php so it gets run by the server, and once you’ve done that you can link to it as if it was a regular css file and make sure the header is correct set with that header code you have at the top of the file
Change:
<link href="https://stackoverflow.com/questions/12367134/css/<? echo $theme;?>/styles.css" rel="stylesheet" type="text/css" />
To:
<link href="https://stackoverflow.com/questions/12367134/css/<? echo $theme;?>/styles.php" rel="stylesheet" type="text/css" />
and top of that file you have
<? header ("Content-type: text/css");?>
And btw since you seem to have php shorttags already enabled you might aswell use instead of using
<? echo $var;?>
Use
<?=$var;?>