Hume's distinction between relations of ideas and matters of fact is one of the first formulations of a distinction that has been instrumental in philosophy ever since. Kant made the distinction famous, calling relations of ideas "analytic" and matters of fact "synthetic." Ever since, and particularly in the development of analytic philosophy in the twentieth century, the analytic/synthetic distinction has been a hot topic of debate.
It might not be clear what Hume means when he says it would be a contradiction to deny relations of ideas, but not matters of fact. Surely, there is something contradictory about saying "it's raining" when the sun is shining brightly. The point is that we need to refer to the world around us to verify matters of fact. The claim that two plus two equals five is a contradiction because nothing in our experience can possibly prove it true. The claim "it's raining" might have been true under other circumstances, and the claim must be compared with reality in order to be proven false.
We can know relations of ideas quite easily by means of what Hume calls demonstrative reasoning. There are well-established axioms and rules of inference according to which I can derive mathematical and other logical truths. Similarly, there are well-established means of knowing observable matters of fact. For instance, my claim that it's raining can be verified by stepping outside or looking out the window. However, Hume notes that unobserved matters of fact are more difficult to sort out. I know that the sun will rise tomorrow, but how? I won't be able to verify that claim directly until tomorrow, but I can still claim to know it with certainty today.
Hume suggests that we use the principle of cause and effect to reason through matters of fact. The principle of cause and effect, he suggests, we learn from experience. The question, then, is how we can ground general principles that we learn from experience. This question cuts right to the very heart of the inductive reasoning that is central both to the scientific method and to Hume's philosophy. All our general principles in philosophy and science are induced from particular examples. Induction essentially consists in observing and predicting the future based on what we have observed in the past. We are absolutely certain that the second billiard ball will move when it is struck, not through demonstrative reasoning, but because we have seen bodies collide in that way countless times during our lives and have never seen one instance to the contrary.
For induction to be a valid form of reasoning, we need to propose some sort of "uniformity principle" that establishes that the future will resemble the past. It may seem obvious that physical laws will not change in the future, but Hume's genius lies precisely in seeing that this is still a claim that needs to be proved and argued for. To his surprise, he finds there is no good reason to trust in any sort of uniformity principle. It cannot be established through reason alone, since its denial is hardly contradictory. It would seem that we learn of this principle through experience, but we cannot claim that it is confirmed in experience. A uniformity principle is needed to justify all inductive claims based on past experience, so we cannot prove the uniformity principle itself through induction. We need to prove the uniformity principle before we can say anything about induction or knowledge from experience, but it seems that we cannot prove the uniformity principle without an appeal to experience. This circularity could be schematized as follows:
Rather than try to hedge at this point, Hume bites the bullet and accepts the consequences of his reasoning: there is no way we can prove any kind of uniformity principle, and so induction is not a valid form of reasoning. Any reasoning about future events is mere conjecture and the claim that the sun will rise tomorrow is no more certain than the claim that aliens will invade the earth tomorrow. Hume is not necessarily claiming that there is no uniformity principle or that there is a good chance that the sun will not rise tomorrow. He is saying that if there is some hidden power that enforces a continued regularity in physical laws, it is beyond the power of our reason to detect it. Our belief in induction is not based in reason but simply in custom. Past experience has led us to believe certain things about future events (and indeed, this experience rarely leads us astray) but these beliefs are not rationally justified. Hume's argument is that we are committed to the belief that the future will resemble the past, but that we are not rationally justified in holding this belief. Reason is a far weaker tool than we might have supposed.