Strictly speaking, tension is not the same as force, although it is sometimes described as the magnitude of the 'pulling force' experienced by an element (such as a rope).
The important thing to remember when resolving forces in classical mechanics and to understand tension is to apply Newton's three laws of motion. They are:
1st Law: an object with no external force will not change velocity
2nd Law: Force = Mass x Acceleration
3rd law: Every applied force (action) has an equal and opposite force (reaction).
So for the one dimensional cases you've given, think of the 'tension' of the rope as the magnitude of any pulling force it would be experiencing, bearing in mind that this tension is not actually a force (it has no direction), whereas the force whose magnitude it has, would be appear to be pulling the rope in opposite directions (as per Newton's 3rd law).
$T\leftarrow\rightarrow T$
So, back to your questions:
1 - When you pull on a rope tied to an immovable object, applying a force $F$, it reacts with force $-F$ (Newton's 3rd law) and the 'tension' in the rope is the magnitude of this force $F$.
$F\leftarrow\rightarrow F$
2 - If you pull on a rope which is tied a mass $M$ (initially at rest and free to move) it will accelerate towards you (Newton's second law). If you keep keep pulling the rope, keeping it taut by applying a constant force $F$ for a time $t$ and then remove the force thereby slackening the rope (no tension), the final velocity of the mass will be $v=at$ (neglecting friction). You can determine the force applied by $F=Mv/t$.
3 - If you apply a force of $X$ Newtons pulling a rope tied to a mass $M$ which I am holding, the tension on the rope is $X$ as long as the mass isn't moving. If I increase my pulling force to $Y$, the resultant force, $F=Y-X$ will pull you along with the mass, towards me. Note that we subtract the forces because they are acting in opposite directions. The resultant force $F$ will accelerate both you and the mass towards me at a rate $a=F/(M+m)$, where $m$ is your mass (assuming the mass of the rope is negligible). The tension on the rope will be equal to the magnitude of resultant force on the rope, which is $T =\lvert X-ma\rvert = \lvert X-m\times \frac{F}{M+m} \rvert= \lvert X-\frac{(Y-X)m}{M+m}\rvert$. Note that if your mass, $m$ is negligible, the tension of the rope becomes $X$, whereas if the mass of the body $M$ is negligible, the tension of the rope becomes $Y$. If your mass is equal to the mass of the body $(m=M)$ then the tension on the rope is $(Y-X)/2 = F/2$.
If I apply a pushing force $Y$ directly to the body of mass $M$, while you pull on the rope tied to it by applying a force $X$, the resultant force on the mass will be $F=X+Y$ (in your direction). The two forces are added not subtracted (since they are applied in the same direction towards you). The body will therefore accelerate in your direction (Newton's second law) under the total force $a=F/M$ and the tension on the rope will be equal to the magnitude of the resultant force, $(F-Y)=X$. Note in this instance, your mass is irrelevant, because the rope does not transmit my pushing force $Y$ to you (a rope does not work under compression!).
4 - If two bodies of mass $M$ are tied together with a rope and are moving in opposite directions at a speed $v$, they will each have momentum with magnitude $Mv$ but in opposite directions. Since neither mass is experiencing a force, they will continue to move at at constant velocities in opposite directions (Newton's 1st law), until the rope between them becomes taut. At that point, they will quickly decelerate and travel back towards each other. The rate of deceleration and subsequent speed at which they will travel towards each other will depend upon the 'elasticity' of the rope as well as the amount of 'friction' in the rope. In the case of an 'inextensible' rope with no friction, the rope will have a non-zero 'impulse' tension only at the instant it is taut. The two bodies will then move towards each other with the same velocity as they were previously moving away from each other (due to conservation of momentum).
Until you realise that tension is not the same as force, you may experience a little tension yourself as you grapple with the concept!
As an aside, you may come across some textbooks on engineering mechanics or materials which describe tension as a type of pressure or stress (force per unit area) as in 'tensile stress' applied to a truss member. If we define the area as a vector whose magnitude is the cross sectional area of the material under stress and whose direction is normal (perpendicular) to the cross sectional area, then the resulting force is the product of stress and area. In the most general sense, since the tension may have a different effect in different directions (anisotropic), the resulting force is not necessarily in the same direction as the area. In a three-dimensional Euclidean space, the tension is a tensor of rank 2. This is a linear transformation (mapping) with $3^{2}$ co-ordinates, something like a (3x3) matrix, which when 'multiplied' by the "area vector" produces the resultant "force vector" (not necessarily in the same direction).
However, since your examples are all dealing with forces in 1 dimension only, we can treat tension as a scalar (that is, a tensor of rank 0) whose magnitude is that of the force exerted by the rope under tension.
A string cannot apply a bending force or a compression force. Only a tension force. That's what the phrase is meaning to convey.
Tension can be due to any source of force, not just hanging weights. Whatever direction the force pulls, that will be the angle of the string. If the string in the figure is in equilibrium, then the force of tension is the same at both ends of the string regardless of the angle.
We can generalize your last sentence: the tension at each point in the string must be such that it balances all of the forces on either side of it. In the case of a massless string that hangs straight down, the tension in equilibrium would equal the weight of the masses. For a massless string at an angle, the tension would equal the applied force at the end of the string, whatever the source of that force is. For a string with nonzero mass hanging straight down the tension at a point must support the hanging weight plus the weight of the string between the point in question and the weight.
Update: what about a non-ideal pulley?
This takes some time to address. The short answer: if the pulley has friction or mass, then the tension of the left side of the string might not be the same as the tension on the right side. Now for the long answer.
The discussion so far applies when the pulley is ideal, that is, it has neither mass nor friction. What happens if the pulley is not ideal? If the pulley is not ideal then we have to consider an aspect of the situation that we've so far swept under the rug: torques on the pulley.
Another complication arises if we allow the string to have mass. We'll ignore that one so that we can focus on the pulley. We will assume that the string and the pulley move together without slipping.
There are four objects to think about. There are two somethings that are applying forces to the ends of the string. One of these might be a hanging mass, and if so, that side of the string will be oriented straight down. If the other end of the string is at an angle, then the something applying the force can't be a hanging mass, it has to be something else. Another object is the string. The fourth is the pulley. The string, however, has two parts: one coming off of the pulley on the left side, the other coming off of the pulley on the right side. Each string "side" is in contact with the pulley. The string is in tension. Therefore, each side of the string will apply a torque to the pulley. This is true for both the ideal pulley and the non-ideal pulley. A non-ideal pulley will have an additional torque if there is friction in the bearing and the pulley is rotating.
The moment of inertia of the ideal pulley is zero because it has no mass. In addition there is no torque due to friction in the bearing. Newton's second law for the ideal pulley is $$\tau_\mathrm{net}=\tau_\mathrm{left}-\tau_\mathrm{right}=I\alpha=0$$ This means that the torque due to the left side of the string has the same magnitude as the torque due to the right part. The pulley has just one radius, of course. We conclude that the forces causing the torques are equal on the left and right. The tension on the two sides of the string are the same. This conclusion is valid regardless of the state of motion of the pulley. At rest, constant rotation rate, or changing rotation rate: the tensions on either side of an ideal pulley are the same. This is why it's so convenient to sweep the issue under the rug.
Now if the pulley is not ideal, this conclusion is not valid. If the pulley is not ideal the torques, and thus the tensions, do not have to be the same on the left and right. In the case of friction, there will be an additional torque to include in the expression for net torque. Consequently, the tensions need not be the same. (But they will be the same if the pulley is not rotating. There's no friction in that case.)
Suppose the pulley has no friction but has mass, and a non-zero moment of inertia. Now if $\alpha$ is zero, that is, the pulley is either not rotating or rotating at a constant rate, then the net torque is zero, and the tensions left and right are equal. If the rotation rate of the pulley is changing, slowing down or speeding up, then $\alpha$ is not zero, and the left tension and the right tension will not be the same.
Best Answer
Tension is not in itself a force. To get an actual force you must choose a division of the rope into two parts. If a horizontal rope is in "tension" and you choose a point P on the rope, then the part of the rope to the right of P pulls on the part of the rope to the left of P with a force T to the right. Similarly the part of the rope to the left of P pulls on the part of the rope to the right of P with a force T to the left.
If instead of a rope you have rod which is in compression then, after choosing a point P, the part of the rod to the left of P pushes on the part of the rod to the right of P with a force to the right, and so on....