Intuition for Cohomology and Holes in a Space
Solution 1:
In my opinion, this is a great question, because it's actually not the right way to measure holes. The construction that measures holes is not cohomology, but just homology. The easiest example of a homology theory is the simplicial homology, where you take a space which can be written as a union of simplices. You fix an ordering on the vertices for the sake of computation, and then you define the chain groups $C^k(X)$ to be the formal linear combinations of simplices in each dimension. The 'differential' decreases the dimension, and is simply the alternating sum of the boundary faces of that simplex. When you have a chain complex with a differential which decreases the rank rather than increase it, we tend to call them 'boundary' operators inspired by this theory.
This turns out to also define a chain complex, because the alternation forces the relation $$\partial^2 = 0$$ because if a simplex has vertices $0, ..., n$, then the boundary is $\sum_{i=0}^n (-1)^i(0,...,\hat{i}, ... n)$ where the hat denotes deletion. When you take the boundary twice, there are two ways to delete a pair of indices, and the difference between them will come with a difference in sign, so they'll cancel.
Now what are the homology groups of such a thing looking like? Well the things killed by the boundary operator are called cycles. The intuition from this is that if you have a loop, and you divide the loop into edges making a polygon, this is a simplicial complex, as described briefly above. Each vertex appears once as a head and once as a tail. So if I write my loop as a sum of these edges and take the boundary, everything cancels and you get 0.
On the other hand, the image of the boundary operator, well, these are just called boundaries, because they are the boundary of something. The quotient is the simplicial homology. It is exactly these that measure holes in a space. The loops which are not boundaries of something filling them in are the holes!
The relationship between homology and cohomology in this way is spelled out over a beautiful collection of theorems forming what is for me the spine of algebraic topology (at least for me as someone predominantly interested in geometry, where mostly I want these tools for computational purposes). First, there are many other homology theories and cohomology theories. The most important theorem(s) relating them is that all the homology theories on reasonable spaces, and satisfying some very modest axioms all compute the same algebraic invariant, so we are justified in just speaking of the homology or cohomology of a space.
On the other hand, homology and cohomology are also related to one another by some special theorems, such as Poincare duality and the Universal Coefficient Theorem.
The rough intuition for Poincare duality (and indeed, a fake proof was given by Poincare himself along these lines) was that there are two reasonable ways of formulating how to dualize a chain complex where the objects look like simplices. One is to replace the simplices with dual simpliices, i.e. replace the vertices with top cells, the edges with second-to-top faces, and so on. The other way is the algebraic construction of a cohomology theory, where you form the dual module of every group in the chain complex, by taking $C^k := \hom(C_k, \mathbb{Z})$. It turns out that there is a dual pairing $C_k(M) \otimes C_{n-k}(M) \to \mathbb{Z}$ given by counting signed intersections, and this pairing can often induce an isomorphism between $k$ chains and $n-k$ cochains, since the boundary operation is essentially carrying all the same data as the incidence relation for the duals.
For this reason, when one is studying cohomology with differential forms, you are actually studying (by one of these theorems that says all cohomology theories that satisfy modest axioms are isomorphic!) studying the geometry of a dual triangulation of your space. This gives you intuition for why they should be similar, but can often be different. Especially when one is studying De Rham cohomology, because there, the coefficients are in the field $\mathbb{R}$, so the coefficients do not allow you to see 'half holes' such as in the projective space. In that space (if you haven't seen this example) there is a loop which does not bound a disk, but if you traverse the loop twice, now it does bound a disk. The general relationship between the different theories' and their coefficients is the purpose of the UCT above. Changing the coefficients can change what your computations can 'see,' but this is another story.
Solution 2:
The intuitive reason for why closed forms detect holes is the existence of Stokes' theorem. One of the consequences of Stokes is, for example, that for a closed $1$-form $\omega$ and a path $c$, the value of $\int_{c} \omega$ is invariant if we move $c$ around via an homotopy. If there is another path $c'$ which has a different value for $\int_{c'}\omega$, then we cannot move $c$ around and end in $c'$, thus "there is a hole" of some kind.
It is also arguably the formal reason, since the de Rham map \begin{align*} \Omega_n(X) &\to \mathrm{Hom}(C_n(X),\mathbb{R})\\ \omega &\mapsto (\sigma \mapsto \int_{\sigma}\omega) \end{align*} depends on Stokes to even be a chain map. The de Rham theorem then says it induces an isomorphism on the cohomology level, and since the right side is singular cohomology you recover the frequently used "holes" analogy.