Using wp_add_inline_style Inside a Template File

Conceptually wp_add_inline_style adds some lines as if they were concatenated to a style file. This means that your setup will only work if you are adding the inline style to a style file loaded in the footer, because by the time you are calling add_inline_style in a template the header has already been assembled.

That said, this is really not a good idea. Functions need to be in the functions.php file to keep your code readable in the long term. If you want to enable users to add different styles per post, the best approach is to make a custom field for that, which you can read in time to enqueue it in the header.