Du’a for Entering Toilet: Why?
Question

When entering the bathroom myself and all my family read the du’a upon entering and leaving. Is this du’a to be read when we use the toilet? As there are times when a person may just go into the bathroom to comb his/her hair, etc.
Praise be to Allah.Du’a when entering the toilet: Why?
The scholars have stated that the reason why it is mustahabb to seek refuge with Allah when entering the bathroom is to seek protection with Him from the devils that frequent places where there are impurities and where ‘awrahs are uncovered. There are ahadith which indicate that. 
Zayd ibn Arqam (may Allah be pleased with him) narrated that the Messenger of Allah (peace and blessings of Allah be upon him) said: “These toilets are haunted (inhabited by devils), so when anyone of you goes to the toilet let him say, ‘A’udhu Billahi min al-khubthi wa’l-khabaith (I seek refuge with Allah from the male and female devils).” (Narrated by Abu Dawud, 6; classed as sahih by al-Albani in Sahih Abi Dawud) 
Al-Hattab said: These places are singled out for seeking protection with Allah for two reasons:

Because they are toilets, and by Allah’s will the devils dominate toilets.
The toilet is a filthy place where one should not verbally remember Allah, so the shaytan takes advantage if one does not remember Him, because remembrance of Allah drives him away. So the command to seek refuge with Allah before that means that one will be protected from the shaytan until he comes out. End quote.

Shaykh Ibn ‘Uthaymin (may Allah have mercy on him) said in al-Sharh al-Mumti’ (1/83): 
The purpose of this seeking refuge is to seek protection with Allah against al-khubthi wa’l-khabaith (the male and female devils) because this is an evil and unclean place (khabith), and the place that is khabith is the abode of al-khubthi wa’l-khabaith (the male and female devils). So it is appropriate when wanting to enter the toilet to say: A’udhu Billahi min al-khubthi wa’l-khabaith (I seek refuge Allah from the male and female devils), so that no khubth (evil) or khabaith (evil spirits) will affect him. End quote.
This reason dictates that the Muslim should always seek refuge with Allah every time he enters the toilet, whether he intends to relieve himself or he is entering for some other purpose for which people use bathrooms nowadays, such as cleaning and so on. Thus the Muslim will protect himself from the harm of the devils. 
It says in al-Mughni (1/190): 
“Ahmad said: He should say when entering the toilet: A’udhu Billahi min al-khubthi wa’l-khabaith (I seek refuge with Allah from the male and female devils). I never entered the place for doing wudu without saying it but something I disliked happened to me.”
Some fuqaha have stated something similar, as it says in Hashiyat Nihayat al-Muhtaj min Furu’ al-Shafi'i (1/142): 
“When taking a child into the toilet so that the child can relieve himself, is it Sunnah for him to say it on behalf of the child or not? There are different opinions concerning that but it is not unlikely that he should say it. 
That also includes the mother wanting to breastfeed her child in the place where he relieves himself, or sitting him on the potty.”
Shaykh Ibn Baz (may Allah have mercy on him) was asked in Majmu’ al-Fatawa (10/29): Is the du’a only for entering the bathroom, or is it only when a person wants to relieve himself? 
He replied that it is mustahabb to say the du'a for entering the bathroom in all cases, without limiting it to when a person is going to relieve himself. 
The same applies to the du’a for leaving the washroom. Al-Tirmidhi (7) narrated that ‘Aishah said: When the Prophet (peace and blessings of Allah be upon him) exited the toilet, he used to say Ghufranaka (Your forgiveness). 
Du’a when exiting the toilet: Why?
The scholars have stated that the reason why one should seek forgiveness when exiting the toilet is that it is for not remembering Allah whilst one was in the toilet. The Muslim regards that as a shortcoming and makes up for it by asking for forgiveness. 
See al-Nihayah fi Gharib al-Hadith by Ibn al-Athir (3/703). 
This wisdom also applies to the one who enters the toilet for a reason other than relieving himself. Seeking forgiveness is the daily habit of the Muslim, so there is nothing wrong with saying it after coming out of the bathroom. 
For more about bathroom-related issues, please see these answer: 26816 , 2532 , 2255 , 42061 and 161383 .
And Allah knows best.