how did Gatsby know Nick was Daisy's cousin in the first place?
There is no incident in the novel where direct mention is made of how Gatsby found out about Nick and Daisy's relation to each other. We can, however, correctly assume that he more than likely heard from Jordan Baker.
Gatsby had picked Nick up and was taking him to New York. During the journey, Jay said:
"I’m going to make a big request of you to-day..."
When Nick requests further information, Jay replies:
"You’ll hear about it this afternoon.”
Nick assumes that Jay himself will speak to him, but Jay informs him that
"... Miss Baker has kindly consented to speak to you about this matter.”
Later that afternoon, Nick and Jordan are sitting in the tea-garden at the Grand Plaza Hotel. She speaks to Nick about her friendship with Daisy, how she had once seen her with Jay and the fact that Daisy had married Tom after Jay did not return from the War soon enough. She also mentions that Daisy had enquired about the name Gatsby and mentioned that she had once known someone by that name. By the time she had finished her story, they had left the hotel and were driving in a car.
Nick mentions that it had been a strange coincidence that Jay had bought his house right across the bay from Daisy and Tom's mansion. Jordan tells Nick that Jay had done it purposely.
Jordan then says:
"He wants to know, if you’ll invite Daisy to your house some afternoon and then let him come over.”
One can gauge from the rest of their conversation that Jordan had told Jay about Nick's connection to Daisy.
“He wants her to see his house,” she explained. “And your house is right next door.”
“I think he half expected her to wander into one of his parties, some night,” went on Jordan, “but she never did. Then he began asking people casually if they knew her, and I was the first one he found. It was that night he sent for me at his dance, and you should have heard the elaborate way he worked up to it."