Answer:
The gills are external because their main function is to extract dissolved oxygen from water. The external location of gills also prevents the entry of extra water inside the body. Entry of excess water may disturb the osmotic balance of the organism which may result in death.
In contrast, lungs are internal as they extract oxygen from the air and their function depends on atmospheric pressure. If the lungs would be external it would be difficult to change the pressure inside the lungs which helps in gas exchange.
In addition, the lungs are needed to be moist, they are very delicate and soft. So, the external location would cause infection, damage, and loss of function of lungs.