The definition of metric space,topological space
Originally mathematics was intended to describe the real world. We then continued to develop it using the intuition of how the real world behaves in order to describe how mathematical objects would behave.
In the 19th and 20th century mathematics had several foundational crises. It turned out that intuition is not a good enough foundation for mathematics. Instead we need to describe certain properties in a formal fashion and use logical rules of inference to deduce properties of mathematical objects.
When this is done, one can easily see that certain properties are enough to discuss certain happenings. For example, if $T$ is a linear transformation of $\mathbb R^2$ then it is surjective if and only if it is injective. However the fact that we are over $\mathbb R$ did not matter, and this is certainly true for $\mathbb R^3$ as well. It turns out that if $V$ is a finitely generated vector space over any field $\mathbb F$ then this is true.
If so, the notion of space tells us that it is a mathematical universe which has certain structure. These properties are the concrete properties we need to generalize the concrete real-world describing phenomenon to a general mathematical context. This abstract is very useful because it allows us to apply the same tools on seemingly different problems, simply by showing that two different objects can be seen as constructs of a similar kind.
Now we return to the particular question, vector spaces; topological spaces; metric spaces; etc. Those are often generalizations of things naturally arising during the intuition-based era of mathematics. For example, $\mathbb R$ is a metric space. It has a very natural metric, the absolute value which tells us how close are two numbers. This notion can be used to define things like continuity of a function, or convergence. It turns out that measuring distance can be done in a different way, and the distance function need only to satisfy several basic properties, to a space in which we can measure distances between points we call a metric space.
Similarly, but less clearly, topology is also a generalization of the real numbers and metric spaces. We notice that we can use open intervals in the real numbers, we notice that a sequence converges to a point $x$ if in every open interval around $x$, all but finitely many points of the sequences appear. Therefore open intervals are a good way to measure convergence. Topological spaces are very much a generalization of this notion, we define sets which we call open, and a sequence converges to a point if in every open set which contains this point almost all the sequence can be found.
Vector spaces rise naturally when solving a system of linear equations in several variables. It turned out that not only we can generalize the number of variables and equations, but also that linear functions can be used to approximate less-linear functions (e.g. differentiable functions), and that vector spaces can be used to describe many more objects in mathematics. For example "all the real-valued continuous functions from the real numbers" has a very natural structure of a vector space over $\mathbb R$. In this vector space integrating can be seen as a linear functional, and taking anti-derivative is a linear operator. Both are very natural to calculus.
All these notions, and much much more, are generalized even further in mathematics. What many mathematicians do is the study of properties, asking "what property would guarantee that a certain consequence is true?", and "what property is necessary for this consequence to hold?". That, in my eyes, the greatest beauty in mathematics. The ability to isolate and generalize properties from the particular case into an extremely abstract case.
You are quite right to ask for the context of these definitions. One place to look in this case is
http://www-history.mcs.st-and.ac.uk/HistTopics/Topology_in_mathematics.html
There are three reasons for abstraction:
To cover many known examples.
To simplify proofs by giving the key reasons why something is true.
To be available for new examples.
Thus the power of abstraction is also to allow for analogies.
One should also mention the amazing extension of the notion of metric space by F.W. Lawvere in
Lawvere, F. William Metric spaces, generalized logic, and closed categories With an author commentary: Enriched categories in the logic of geometry and analysis. Repr. Theory Appl. Categ. No. 1 (2002), 1–37.
Another comment of Lawvere was that the notion of "space" was developed to deal with "motion" and "change of data". This theme is developed in my lecture Out of Line.
Later: You should also realise that one of the driving forces of abstraction is laziness! Thus suppose we are working in the space $\mathbb R^3$ with the usual Euclidean distance, and have two points, say $P=(x,y,z), Q=(u,v,w)$. After a time we might get fed up with writing down the formula for the distance from $P$ to $Q$ and decide to abbreviate it to $d(P,Q)$. Then you start asking yourself what properties of $d(P,Q)$ am I really using, and it may be a surprise to find how few of these you need for the proofs, and how much easier it is to use these properties to write down the proofs and to understand them. Thus these properties of $d$ become the underlying structure for this situation. You find that you really understand why something is true. Then you find that these properties apply to more examples, and you are well away to an "abstract" theory.
Again the pressure might be to apply arguments you have used in one situation in another, but the notion of distance does not immediately apply. Hence the notion of "neighbouhood".
After many years it was found that in many situations the notion of "open set" is easier to work with, and has a logically simpler set of rules. So this comes to be thought of as THE definition of a topological space, and the poor students often get presented with this definition with no history, no motivation, no background, but a command to learn it! (Protests not allowed, either! We all know that the writer of:"Give pepper to your little boy/And beat him when he sneezes./He only does it to annoy,/ and can stop whenere he pleases." was a mathematician!)
One of the reasons for abstraction is also that analogies are not between things but between the relations between things. So knots are quite unlike numbers, but the rules for the addition of knots are analogous to the rules for multiplication of numbers. So one can define a "prime knot", and ask: are there infinitely many prime knots? This is how mathematics advances, often for lack of a simple idea. As Grothendieck wrote: "Mathematics was held up for thousands of years for lack of the concept of cipher [zero], and nobody was around to take such a childish step."
Grothendieck has also argued in Section 5 of his famous "Esquisses d'un programme" (1984) against the concept of topological space, as being inadequate to express geometry, or at least the geometry he had in mind. So there is nothing sacrosanct about these concepts, and their applicability and disadvantages need to borne in mind.
In a college debate (years ago!) I was taken to task by a more experienced debater who quoted: "Text without context is merely pretext." I believe that the import of this applies also to mathematics, and relates to my initial remarks.
I don't think that you will find that there were specific problems in mind in the development of these more abstract concepts. In terms of topological spaces, around the time of the development of a rigourous foundation for the calculus, mathematicians had to come to grips with what exactly a real number was, and what properties the real line had. They also discovered that they could apply certain ideas and methods from the familiar Euclidean spaces to "spaces" which were quite unlike these. As these ideas and methods gained more use, it was natural to attempt to find the central core of these arguments and develop a general theory about these sorts of "spaces".
The following is taken directly from Engelking's text (General Topology):
The emergence of general topology is a consequence of the rebuilding of the foundations of calculus achieved during the 19th century. Endeavours at making analysis independent of naive geometric intuition and mechanical arguments, to which the inventors of calculus I. Newton (1642-1727) and G. Leibniz (1646-1716) referred, led to the precise definition of limit (J. d'Alembert (1717-1783) and A. L. Cauchy (1784-1857)), to formulation of tests for convergence of infinite series (C. F. Gauss (1777-1855)) and to clarifying the notion of a continuous function (B. Bolzano (1781-1848) and Cauchy). The necessity of resting calculus on a firmer base was generally recognized when various pathelogical phenomena in convergence of trigonometric series were discovered (N. H. Abel (1802-1829), P. G. Lejuene-Dirichlet (1805-1859), P. du Bois-Reymond (1831-1889)) and the first example of nowhere differentiable continuous functions were described (Bolzano, B. Riemann (1826-1866) and K. Weierstrass (1815-1897) in 1830, 1854 and 1861, respectively). The latter examples unsettled common outlooks and led to a revision of the notion of a number and to the rise of rigorous theories of real numbers. The most important ones were: the theory proposed independently by Ch. Méray (1835-1911) and by G. Cantor (1845-1918), where real numbers were defined as equivalence classes of Cauchy sequences of rationals, and the theory due to R. Dedekind (1831-1916), where real numbers were defined as cuts in the set of rationals. Both theories gave a description of the topological structure of the real line.
General topology owes its beginnings to a sequel of papers by Cantor published in 1879-1884. Discussing the uniqueness problems for trigonometric series, Cantor concentrated on the study of sets of "exceptional points", where one could drop some hypotheses of a theorem without damaging the theorem itself. Later he devoted himself to an investigation of sets, originating in this way both set theory and topology. Cantor defined and studied, in the realm of subsets of Euclidean spaces, some of the fundamental notions of topology. Further important notions, also restricted to Euclidean spaces, were introduced in 1893-1905 by C. Jordan (1838-1922), H. Poincaré (1854-1912), E. Borel (1871-1956), R. Baire (1874-1932) and H. Lebesgue (1875-1941).
The decisive step forward was the move from Euclidean spaces to abstract spaces. Here, Riemann was the precursor; in 1854 he introduced and studied the notion of a two dimensional manifold and pointed out the possibility of studying higher dimensional manifolds as well as function spaces. Around 1900, when fundamental topological notions were already introduced, a few papers appeared exhibiting the existence of natural topological structures on some special sets, such as: the set of curves (G. Ascoli (1843-1896)), the set of functions (C. Arzelá (1847-1912), V. Volterra (1860-1940), D. Hilbert (1862-1943) and I. Fredholm (1866-1927)) and the set of lines and planes in the three dimensional space (Borel). In this way the ground was prepared for an axiomatic treatment of the notion of a limit and, more generally, the notion of proximity of a point to a set.