In this answer I argued that Dumbledore specifically gave Hagrid various jobs and responsibilities in order to help Hagrid. That is to say that Hagrid who had never completed his magical education, and was a half-giant, had very little opportunity to excel. Most tasks in the magical world require a sufficient mastery of magic, something which Hagrid lacked. Dumbledore would always find tasks that could be done without expert magic, and assign those to Hagrid. For example, retrieving Harry from Godric's Hollow, transporting the Philosopher's Stone, etc.
At the most basic level we could view this as kindness on Dumbledore's part. Hagrid was a kid with no father, an unknown giantess mother, expelled from Hogwarts, with no apparent future. Dumbledore took him in, and became a sort of father figure to Hagrid. While everyone else rejected Hagrid, Dumbledore felt bad for him and did whatever he could to help him.
However, since this is Dumbledore we're talking about, we would be remiss if we did not look for a more nefarious motive as well. Dumbledore presumably realized that the more he helps Hagrid, the more Hagrid will be loyal to him in return. As I argued in this answer Dumbledore succeeded to the point where Hagrid's loyalty was such that Dumbledore could trust Hagrid with his life, knowing that Hagrid would unquestioningly do anything that Dumbledore asked of him. This degree of loyalty is not usually something that one earns overnight. Presumably, as Dumbledore helped Hagrid more and more, Hagrid's loyalty to Dumbledore steadily increased. Dumbledore stood to benefit from this arrangement, as there are certain tasks that Hagrid was uniquely suited for. For example, Hagrid was the perfect person to send to the giants following Voldemort's return. If someone other than Dumbledore had asked Hagrid to do that, would he have acquiesced? Perhaps. Or perhaps not. Appointing Hagrid as a teacher was just about the best thing Dumbledore could do for him, as we see in Prisoner of Azkaban when his teachership is announced:
Harry, Ron, and Hermione, however, were eager for it to finish so that they could talk to Hagrid. They knew how much being made a teacher would mean to him.
"Congratulations, Hagrid!" Hermione squealed as they reached the teachers' table.
"All down ter you three," said Hagrid, wiping his shining face on his napkin as he looked up at them. "Can' believe it... great man, Dumbledore... came straight down to me hut after Professor Kettleburn said he'd had enough.... It's what I always wanted...."
This would hardly be the only time Dumbledore did something like this. We find something very similar with Mundungus Fletcher. In the beginning of Order of the Phoenix Harry asks Sirius why Mundungus is in the order:
"How come he’s in the Order?" Harry said very
quietly.
"He’s useful," Sirius muttered. "Knows all the crooks
— well, he would, seeing as he’s one himself. But he’s
also very loyal to Dumbledore, who helped him out of
a tight spot once. It pays to have someone like Dung
around, he hears things we don’t.
We see here that Dumbledore has earned Mundungus's loyalty by helping him out, and we learn that having Mundungus's loyalty is very useful. While it's possible Dumbledore would have helped Mundungus anyway, it is unlikely that he did not think of the benefit he would accrue by having someone like Mundungus in his debt.
Now if we accept that Dumbledore wanted to appoint Hagrid either out of kindness to Hagrid or to earn (solidify) Hagrid's loyalty, the question becomes one of trade-off. What price would Dumbledore be willing to pay to accomplish these goals?
Having Hagrid as the Care of Magical Creatures teacher is not the most dangerous thing in the world. I don't think the hands on the Weasleys' clock pointed to "Mortal Peril" every time they attended Hagrid's classes. This is not to deny that there was any danger altogether. There surely was. However, attending Hogwarts itself carries a certain degree of danger. As Harry thought in Chapter Two of Goblet of Fire:
He was used to bizarre accidents and injuries; they were unavoidable if you attended Hogwarts School of Witchcraft and Wizardry and had a knack for attracting a lot of trouble.
Note, that in all the years of Hagrid's teaching there were no fatalities, or even serious injuries. The only real injury was Malfoy's arm in Prisoner of Azkaban and even that was a joke. Of course, there was potential for greater injury, but that is something that Dumbledore would have to weigh against his other goals, and it is possible that the concern for danger would be outweighed.
Consider a similar circumstance from Half-Blood Prince. Dumbledore knew that Malfoy was trying to kill him. However, he wanted to protect Malfoy's soul by having Snape kill him instead. He also wanted to not appear to know about Malfoy's plan so that Voldemort wouldn't punish Malfoy. So what did he do? He let Malfoy bumble around the school trying to kill him in crude ways that — but for a bit of luck — would have killed two students. Granted, Dumbledore did appoint Snape to keep an eye on Malfoy, but that clearly wasn't enough. So it seems that Dumbledore was not averse to risking the lives of his students in the service of an important goal.
Moreover, we don't know what went on behind the scenes. For all we know Dumbledore was keeping a very close eye on Hagrid's teaching activities, ready to swoop in at a moment's notice should it become necessary. Had there ever been a case where a student came close to being seriously injured or killed, perhaps he would have removed Hagrid from his post.
As for the issue mentioned in the question of Hagrid's temper, in fact both examples are cases where Hagrid attacked someone out of loyalty to Dumbledore. This, is precisely why Dumbledore did hire Hagrid according to my argument above. Dumbledore wanted that kind of loyalty (even if he wouldn't necessarily approve of the particular manifestation in those two cases).
An alternative possibility is that Dumbledore was actually not aware of the danger of having Hagrid teach Care of Magical Creatures. How much did Dumbledore truly know about Hagrid's obsession with monsters? It is unclear from the books whether Dumbledore ever found out about Aragog or Norbert. And Dumbledore also in general had a pretty laissez faire approach to his teachers. We never find him getting involved in what actually goes on in the classrooms. There were at least three teachers in Harry's time (Lockhart, Umbridge, and Trelawney) who didn't teach anyone anything useful, and one teacher who showed, and subjected students to, illegal curses, but Dumbledore is never shown to have done anything about this. While in each case he may have had a specific reason for not getting involved, it is also possible that he simply did not keep tabs on the day-to-day classroom events. If so, he may have hired Hagrid assuming he wouldn't do anything too dangerous, and then simply not followed up to make sure of this.