Essentially, the functionality of this feature is like an auto complete text box. As you type, the code reads the text in the textbox and sends it to a server page or API endpoints along with other necessary information. The server page then queries a database table to retrieve a list of your friends' names which are displayed under the text box. When a user selects a name from the list, another JavaScript function is invoked to save it to the database table for tagged people.
Luckily, there are numerous plugins available that can help implement this feature with minimal customization. One library worth exploring is jQuery UI, which offers an Auto complete feature. Additionally, there are many other libraries out there that can achieve similar results. A quick Google search can point you in the right direction to get started.