Why is (co)homology useful and in which way? I often hear people saying that (co)homology is really useful in many areas of mathematics.

In which way is (co)homology used in different areas of mathematics to prove theorems?

I only know one example: the proof of Brouwer's fixed point theorem uses homology: every continuous function $f\colon D^n\to D^n$ has a fixed point, where $D^n$ is the $n$-disk. Suppose not. Then construct a continuous map $h\colon D^n\to S^{n-1}$ by sending each $x\in D^n$ to the intersection of the line connecting $x$ and $f(x)$ with the boundary $S^{n-1}$ of $D^n$. Now, note that $h$ has a right inverse, given by the inclusion
$$i\colon S^{n-1}\to D^n, \, x\mapsto x,$$
that is,
$$h\circ i=\mathrm{id}_{S^{n-1}}.$$
Then, by the functoriality of the homology functor $H_{n-1}\colon \mathbf{Top}\to\mathbf{Ab}$, it follows that
$$H_{n-1}(h)\circ H_{n-1}(i)=\mathrm{id}_{H_{n-1}(S^{n-1})},$$
which implies that $H_{n-1}(h)\colon H_{n-1}(D^n)\to H_{n-1}(S^{n-1})$ has a right inverse (in particular is surjective). But this can't be possible, since $H_{n-1}(D^n)$ is the trivial group, whereas $H_{n-1}(S^{n-1})$ is infinite.
So using homology, every property of the category $\mathbf{Top}$ (e.g., whether a certain morphism has a left inverse) gets translated into a property of the category $\mathbf{Ab}$ (and, by contraposition, if a property isn't true in $\mathbf{Ab}$, then it can't be true in $\mathbf{Top}$).

Has every use of (co)homology the form of the above argument, i.e., uses that properties of the category $\mathbf{Top}$ get translated into a property of the category $\mathbf{Ab}$?

I would think no, because I doubt that interesting properties can always be formulated as categorical properties.
But then, can (co)homology be used in another way? For instance, I heard that cohomology was used in the proof of the Weil conjectures, and I also heard that there's a cohomology theory (Group cohomology) which can be used in group theory. This seems crazy. I just want to get a clue at why (co)homology is useful in these areas and how it is applied there.
 A: This question is extremely broad, and a lot of ink has been spilled on the subject of "why is cohomology useful" (see, for example, here, here, here, here, here, here, here, or here, all from the first page of google results for exactly that search).
That said, I can answer your question about whether it must always be used in the way you outline (detecting nonexistence of topological features by showing nonexistence of algebraic features): No. There are lots of other uses which do not follow this outline.
One modern view of cohomology is that it witnesses the obstructions to solving some equation.
This is most simply seen in De Rham Cohomology, where we want to solve a differential equation $df = g$. It turns out that locally we can always solve this equation, but globally we might not be able to. The "obstruction" to solving this equation is also topological! If our space is simply connected then we can always solve it. Indeed, we can always integrate a function defined on $\mathbb{C}$, say. But there are nice functions defined in the punctured plane which have no global antiderivative. The famous example is $\frac{1}{z}$.
We might also be interested in solving the equation $f^2 = g$. Again, we know how to do this locally, but there might be no way to solve it on the whole complex plane at once. Also again, we find the obstruction to solving this equation is cohomological.
As a more algebraic example, say you want to solve $x^n = y$ in some field $k$. Then we know how to solve this equation in some algebraic closure $\overline{k}$, and we know that a solution to this equation in $\overline{k}$ actually exists in $k$ if and only if that solution is fixed by the action of the galois group $G$. So we find ourselves interested in the cohomology of $G$.

More concretely, how does this work? Well if we have a mapping between some objects (in the examples above, the mappings were $d$, $(-)^2$, and $(-)^n$ respectively) we can "solve" an equation exactly when we understand the image of the mapping.
For example, we can solve $df = g$ exactly when $g$ is in the image of $d$, or $f^2 = g$ whenever $g$ is in the image of $(-)^2$, etc.
The key idea is to use exact sequences to turn the question of being in the image (which is hard) into the question of being in the kernel (which is comparatively easy). Cohomology theories (and more generally derived functors) give us access to long exact sequences which we can use to check if an equation is (globally) solvable.
For example, let $\mathcal{F}^\times$ be the sheaf of nonnvanishing holomorphic functions on $\mathbb{C}$ under multiplication. Then we have a short exact sequence
$$
0 \to \{ \pm 1 \} \to \mathcal{F}^\times \overset{(-)^2}{\to} \mathcal{F}^\times \to 0
$$
Now our function $g$ is a section of $\mathcal{F}^\times$, and we want to know if it's the image of a section of $\mathcal{F}^\times$ under $(-)^2$. That is, if we can find an $f$ with $f^2 = g$.
Well, we apply sheaf cohomology to this exact sequence to get a (long) exact sequence
$$
0 
\to H^0(\mathbb{C}, \{ \pm 1 \}) 
\to H^0(\mathbb{C}, \mathcal{F}^\times) 
\overset{(-)^2}{\to} H^0(\mathbb{C}, \mathcal{F}^\times)
\to H^1(\mathbb{C}, \{ \pm 1 \})
\to \cdots
$$
Here $H^0$ of a sheaf is exactly the global sections. So $g$ lives in the second copy of $H^0(\mathbb{C}, \mathcal{F}^\times)$. We want to know if it lies in the image of the first copy, and we can do that by checking if it lies in the kernel of the map to $H^1(\mathbb{C}, \{ \pm 1 \})$. One of the magical things about cohomology is that in special cases we can often compute these cohomology groups and the maps between them! So we can actually use this machinery to check if a solution exists.

I hope this helps ^_^
