Each new topic gets a single line within the ubbt_TOPICS table.
FROM THE SCRIPT:
$opid = $topic_info['USER_ID'];
$topic_info['USER_ID'] is the USER_ID stored in the ubbt_TOPICS table for that TOPIC.
FROM THE TEMPLATE:
{if $postrow[post].userid eq $opid}OP{/if}
$postrow[post].userid is the USER_ID of that single post from the ubbt_POSTS table.
Conclusion, if the USER_ID of that single post matches the USER_ID of the TOPIC, then "OP" is displayed.
Feel free to open up both the script (scripts/showflat.inc.php @ ~ line 205) and the template (templates/default/post_side.tpl @ ~ line 101, and ~ line 127) and read it yourself.