Two men who brought explosives to a protest outside New York City's mayoral mansion said they were inspired by the Islamic State extremist group, a court complaint said.