Nahiem Pettiford robbed two men at gunpoint after he was unable to get into the donation box at a Jersey City mosque on Jan. 20, police said.
Pettiford was taken into custody by Jersey City police on Jan. 26 in Newark.
Police searched his car and found more than 300 bags of heroin, a handgun, ammunition and two credit cards he is accused of stealing from the men at the mosque.
Hudson County Superior Court Judge Paul DePascale on Tuesday ordered Pettiford held through his prosecution.
According to the criminal complaint, Pettiford stole a wallet containing about eight to 10 credit/debit cards, $1,400 in cash, an iPhone and a set of keys.
He also stole $100 in cash and purchased about $250 in merchandise with the stolen credit cards, the complaint reads.