Nolan is the man behind the Dark Knight trilogy, and sparked much discussion when he cast Ledger as the iconic antagonist.
In the end, Ledger went on to posthumously win an Academy Award for Best Supporting Actor, as well as a Golden Globe and BAFTA.
Nolan told Entertainment Tonight: “When I cast Heath Ledger as the Joker, it raised a lot of eyebrows and caused a lot of comment.
“I have to trust my instincts, and Harry was perfect for this part.”
Styles, 23, only has a small role in Dunkirk but his inclusion has dominated the build-up to the war drama’s release on July 21.
Fionn Whitehead, who also stars, recently said: “He’s great, he’s a good actor and a lovely guy.
“I think the hysteria – [perhaps] it should have been expected when you take a figure like that and give him a short back and sides and put him in a uniform.
“I think it’s got a bit silly really. The meaning has got lost somewhere along the way and people have stopped realising there’s an amazing cast – including Harry – but there’s, you know, the creme de la creme of actors.”
Speaking to Digital Spy, he added: “I think the focus should not be Harry Styles doing a movie, it should be on the piece in general or his ability to act. And he’s great.
“People are putting too much emphasis on Harry being in it, but that is in no means a reflection on him.
“He hasn’t asked for any of this. In terms of the media, they have put too much emphasis on this one guy instead of the piece as a whole and the ensemble as a whole.”