Why does the corrosion of a steel nail develop iron ions in the ends of the nail and hydroxide in the middle of the nail?
Very good question and thought provoking too. It appears that the nail somehow knows or is it is able to decide which part will be a cathode and which part will be an anode! Why is that so? Why one end was not a cathode and the other end an anode, just the one shown in the cartoon taken from here Imaging metal corrosion



So the fact you should keep in mind is that corrosion is superficially a random process just like cancer. Corrosion comes from corrodere "to gnaw to bits, wear away," it can start from any defect on the metal (scratch, impurity, etc.). However once it starts, just like cancer, it decides its propagation (i.e., the flow of electrons), hence the direction of cathode or an anode. It is likely that in your case the nail tip and the head had more defects than the center, so corrosion started at the tips. The pattern you are seeing is not universal or a fundamentally symmetric phenomenon.

Let us now bend a nail, create stress or defect in the center. Now the corrosion also starts in the center. Have a look at this gallery. Corrosion gallery