How to programmatically update node title?
To do this, you have to use hook_node_presave(). 

It's called before saving the node to the database. (both new nodes and edits). 
Note that you must make sure that you are saving sanitized and formatted data.