John Boyne, the author of The Boy in the Striped Pyjamas, has hit back at those who criticised him for writing about a boy struggling to cope with the transitioning of his sibling.

Boyne’s new novel for young readers, My Brother’s Name is Jessica, was attacked on social media and the novelist was criticised for writing about an issue with which he is unfamiliar.

But Boyne told Hay festival that was the point. “I’ve always said the worst advice you can give to young writers is write about what you know,” he said. “Write about what you don’t know. If we only write about what we know, it’s all biography.

“There is this awful thing, in my opinion an awful thing, #OwnVoices [which says] that people can only write about their own experience and stories, and my experience as a reader and as a writer is the opposite to that.”

He said he had written books about the Holocaust, first world war soldiers, the Russian revolution and the Bounty. “I’ve never been to any of those places, I’ve never done any of those things and nobody ever criticised me for it. If we say we can only write about our own experiences, the corollary of that, for example, is that a transgender writer can only write about transgender characters.

“I don’t feel it’s my job as a reader or a writer to tell anyone what they can or can’t write. We are supposed to use our imaginations, to put ourselves into the minds and the bodies of others.”

He was supported from the Hay audience by the Horrid Henry writer, Francesca Simon: “I am American and I am female and my main character is a little British boy.”

She said if she had to write about her experience, “I would be writing about American Jewish girls who grew up in Malibu on the beach”.

Boyne is gay and grew up in 1980s Dublin when homosexuality was illegal. He said he knew what it was like to feel different: “But even if I didn’t, that should not prevent me from writing that book. Anyone can write it.”

He said he people had accused him of misgendering the book’s title, that it should be My Sister’s Name is Jessica instead. But, he said, the whole point was that the story was through the eyes of the transitioning character’s younger brother Sam. “To be so politically correct, some people … it must be painful to be so woke all the time.”

Boyne said he found sentiments such as “stay in your lane” troubling. “It’s arrogant. A lot of the time it’s about people trying to tell you they are morally superior to you; they know how these things should be written.”

Boyne is the author of 17 novels for adults and children with Striped Pyjamas, adapted in to a film, being his most famous.

He said the abuse on social media was a drain. “If it ruins your day you’re not going to get any writing done.”

Asked about his next book, which is on its fourth draft, Boyne said it was different again. It is set in 52 countries, and begins in the year zero and ends in 2080 on a space station. “It’s the most bonkers book I’ve ever written. I don’t know if it’s completely stupid or it makes any sense but it has been a lot of fun to write.”