You are going to want to take a look at the Auth.php class in ./system/libraries/Auth.php. This class is an abstraction of the authentication API's and allows you to do exactly what you want. The "loggin as user" feature uses these same methods, as well as the member module.
You can also take a look at the Authenticate module (which is free) so you get an idea of how others work with the Auth class.
https://objectivehtml.com/authenticate
Here is some pseudo code for you to use:
// Fetch the member from the DB using whatever logic you need
$this->EE->db->where('username', 'some-username');
$member = $this->EE->db->get('members');
$this->EE->load->library('auth');
// Load a new Auth_result object which logs in the member
$authed = new Auth_result($member->row());
$authed->start_session($cp_session = FALSE);
$member->free_result();
This code should work, but I didn't not have time to execute it, which is why it's considered pseudo code.
I should also add that I am not sure if this even the best way to solve your problem. I am simply answering the questions of "how to programmatically login a user without knowing their password and without submitting a login form."