After some chat in HQ with Petr it seems that the role_unassign() function itself includes the necessary code to delete, for COURSE contexts, the associated user_lastaccess record if the user hasn't anymore the course:view capabilty.
But some sites can show orphan records that never are deleted from that funcion, so I would introduce one new iterator in cron.php in order to detect and delete all those orphan records from user_lastaccess.
Call this the ORPHAN_USER_LASTACCESS_PROBLEM from now. Patch attached. Requires approval, plz.
Patch applied and working.