How to change the page title from functions.php

If you refer to the post title you need to hook your function to the_title filter like explained in the codex.

add_filter('the_title', 'my_custom_title', 10, 2);

If you refer to the HTML meta in your page then you need to hook your function to document_title_parts filter explained here.

add_filter('document_title_parts', 'my_custom_title', 10, 2);

The two filters work differently as the first passes the title as a string and the second an array which contains the title as well.
So depending on which one you need your code will need to be adapted to work accordingly.

If you can explain better your needs a better answer can be given.