An author can choose the name under which he or she publishes. It does not have to be the person's legal or birth-certificate name. When the book was first published they targeted it at boys so she used an initial and joanne used kathleen after her grandmother because she didnt have a middle name.
At first, J.K.Rowling wrote books for her son. So I suppose her son was her inspiration, along with boredom. She was on a train and needed something to do and by the end of the train ride, she had the whole plot in her head.