I am not sure what the question is, but will try to answer anyway. This is basic general topology stuff, sorry if you meant something deeper in your question.

For any topological space $X$ and any equivalence relation $\sim$ on $X$ there is a natural topology on the quotient $X/\sim$, see e.g. this Wikipedia article. Intuitively, the quotient space is the result of "gluing together" all points in every equivalence class of $\sim$.

Making a surface from a polygon is a partial case. For example, the gluing scheme $aabb$ represent the following equivalence relation on a square $ABCD$: an interior points is not equivalent to anything but itself, a point $X$ on the side $AB$ is equivalent to a point $X'$ in $BC$ such that $AX:XB=BX:XC$ and similarly for the sides $CD$ and $DA$. By transitivity, all four vertices $A,B,C,D$ are in the same equivalence class. (In other gluing schemes, such as $abab$, the vertices can form more than one equivalence class.) The quotient space is a Klein bottle. In general, it is easy to prove that for any gluing scheme of a $2n$-gon (where every letter appears exactly two times) the resulting quotient space is a compact surface without boundary. Then there is a topological classification of such surfaces, and so on.

Note that you don't have to begin with a polygon. Any shape homeomorphic to a polygon (e.g., a 2-dimensional round disc) will work the same way because homeomorphic spaces are identical from the topological perspective.

Speaking about generalizations, once you have defined a topological space that serves as a "generalized polygon" and an equivalence relation (the gluing rule) on it, you get a valid topological space as a quotient. However it can be some "weird" space rather than a surface, and it may depend on how exactly you generalize the notion of a polygon.

For example, if you asked about a two-sided infinite string like "$\dots a_{-1}a_{-1}a_0a_0a_1a_1\dots$", it would be natural to take the half-plane as a "polygon", divide its boundary into unit segments and glue them according to the string. Sometimes the result is a (non-compact) surface, sometimes it is not. Namely, if every equivalence class is finite, the quotient is a surface (= two-dimensional manifold), otherwise it is not (because it is not locally compact). In my example, all "vertices" end up in the same equivalence class, so the quotient is not a surface.

Alternatively, you could pack these infinitely many segments around a circle. In this case the quotient is compact but most likely it will fail to be a surface around accumulation points.

You second example is clear. You identify points $x$ and $y$ if $x+y=1$. Equivalently, you could divide the circle into two segments $[0,1/2]$ and $[1/2,1]$ and apply the gluing scheme $aa^{-1}$ to this "2-gon". The resulting surface is the sphere. Another well-known construclion is to identify every point on the circle with the opposite one - this is the same as "$aa$" gluing and the result is the projective plane. However if you make some weird pairwise identification, most likely the result will be some weird topological space.