Arpaio had been convicted of contempt of federal court for violating a judge's order to stop detaining people simply because he thought they were illegal aliens. Trump pardoned him after he was convicted but before he was sentenced.
The President had originally tried to stop the prosecution. However, the Justice Department refused to condone what would have been, effectively, criminal obstruction of justice by Trump (details here), an action that could now come back to haunt him.
Whilst Trump's pardon itself is almost certainly legal, by doing so he immediately set off a firestorm of controversy and condemnation from both Republicans and Democrats. Not only did he pardon a hateful racist, who also has a history of being anti-LGBT, he showed complete disdain for the American judiciary system.
Arpaio wasn't convicted of an ordinary crime. He was convicted of repeatedly ignoring and defying a federal judge.
By pardoning Arpaio, Trump demonstrated a total disregard for the rule of law. If you're a friend of Trump and defy a judge, he's got your back.
Trump claims to be the "law and order President," but he's the exact opposite. This is the sort of corrupt thuggery we could expect to see in Vladimir Putin's Russia or any other kleptocratic dictatorship.
Not surprisingly, the op-ed pages and legal columnists have been excoriating Trump for this pardon. I think the best piece I've read so far is by Adam Liptak, a lawyer who writes for The New York Times, who penned a piece with the title "Why Trump’s Pardon of Arpaio Follows Law, Yet Challenges It" (link here).
If you want to understand why this pardon was so dangerous and frankly un-American, then Liptak's piece is a good place to start. It proves the old adage that "what is legal isn't always what is right."