This is because all firms in perfect competition are by definition selling an identical (homogeneous) product.
If all firms are selling an absolutely identical product, there is no possible reason why someone would pay a higher price to Firm A than they would pay to Firm B. Because of this, any firm that raised its price would lose all its market share.
The curve is also like this because firms in perfect competition make no economic profit. If they drop their price, they will go out of business.
So, they can't raise their prices and they can't lower their prices. That means their demand curves are horizontal.
Here is a video explaining the concept:
A perfectly competitive market is just a fancy way of saying that all the suppliers within a given market are selling a product that is the same in every aspect. Therefore, a consumer does not have the motivation to choose one product instead of the other since both products are completely similar. This results in an economic equilibrium in which both suppliers find themselves reliant upon one another. For example, if one supplier raises their price, then they will be out-competed since they are selling a completely identical product. This results in a demand curve that is horizontal since it represents the static nature of a perfectly competitive market. In other words, the curve is horizontal (perfectly elastic) because it represents a market that is completely balanced and fair, where suppliers are able to consistently produce their goods at market price, earning just enough to keep their business running. Unfortunately, perfectly competitive markets are, for the most part, theoretical. Real-world markets rarely behave in this manner.
By definition, a perfectly competitive market is one in which there are many suppliers and no single supplier is dominant enough to influence either the market price or the total market supplies. This means that each supplier is able to meet at the most a small part of the total market demand.
Because of the limitation on total quantity of a good a supplier is able to produce, there is no effect on the total market supplies by action of a single supplier. Also a supplies is able to sell all the quantity it can produce at the prevailing market equilibrium price. However it will not be able to sell even one unit at a price higher than the market price, as there are other suppliers willing to supply the same good at the market price. This situation results in a firm in a perfectly competitive marked facing a horizontal or perfectly elastic demand curve.
A supplier, if it so wishes, may sell its product at a price lower than the market equilibrium price. But the supplier has no economic motivation to do so, as it can sell all it can produce at market prices.