how or where wordress collect unlogged user session

unlogged users do not come with nothing. so it’s easy: no-where. for the comments scenario you describe, wordpress creates cookies. cookies are fairly well integrated with PHP, you can find out more about that part of PHP here: http://php.net/manual/en/features.cookies.php

Have fun!