Short answer.
In your example, the rope can not be massless (otherwise its acceleration would be infinite), but if it has mass, then tension is different on each point of the rope. Therefore you have to assume there is an object connected to it. Depending on which side of the rope you assume the object is, you get tension 20N or 30N.
This does not contradict the vertically lifted object by a rope. In that case the acceleration would be $a=\frac{T-w}{m}=\frac{T-mg}{m}$, that is $ma=T-mg$, that is $T=ma+mg$. What you are missing is that in this case $mg$ is the weight of the object, which does not affect the tug of war case (since its horizontal).
Long answer
Tug of war
If you pull the leftmost piece with 20N and rightmost with 30N, you would get 10N on a 0 mass object, meaning infinite acceleration. Therefore you have to assume there are two bodies (actually only one would be enough). So, one person pulling on each side of the rope.
Assuming the rope is massless, and is consisted of lots of tiny pieces, we can see that each tiny piece has two forces on it. $F_l$ from the left and $F_r$ from the right. Since acceleration of each tiny piece is $a=\frac{F_r-F_l}{m}$ and m->0 then $F_r$ = $F_l$, otherwise $a$ would be infinite.
Also, this means that any piece of the rope, including the ones that connect to the bodies, pull adjacent pieces with the same force. That is, body A and body B are both pulled by the rope with the same force $T$, which is the tension.
There is $F_A=20N$ on the left body and $F_B=30N$ on the right, plus $T$ and $-T$ respectively. Since bodies A, B and the rope have the same acceleration (if they didn't, they'd move apart from each other), we get:
$a=\frac{T-F_A}{m_A}=\frac{F_B-T}{m_B}$ , meaning $T=\frac{m_AF_B+m_BF_A}{m_A+m_B}$.
If $m_B$->0 then $F_B-T=0$, and $T=F_B=30N$. Likewise if $m_A$->0 then $T=F_A=20N$.
You can not assume that $m_B=m_A=0$ without $F_A=F_B$, therefore you need at least one non 0 mass object attached to the rope.
Upwards pulling
If $m_B=0$ then you get the same result as the vertically pulled body, excluding the weight $w$ of the object ($w=mg$), because when pulling horizontally its weight has no effect.
The best way to define tension is as the one dimensional version of the stress tensor. So, you can define the tension at some point P in the string as the force at which the part of the string on one side of P pulls on the other side of P. The direction of this force then depends on which sides you are considering, so you should make some choice here and relative to that choice the tension is well defined.
Suppose that a sting hangs over a pully, as a result the direction of tension changes. But how do we explain that the magnitude of the tension is the same on both sides? If you are stuck with defining tension as a reaction force to whatever is pulling on it from its ends, then you'll not be able to even address this question. Most likely you'll just assume it's the case without really understanding why.
With the proper definition, you can do a balances of forces calculation along the string at the points where it makes contact with the pulley. If you do this, you'll see that it boils down to the fact that the pully exerts a force perpedicular to the string, this has the effect of changing the direction of the tension, but not its magnitude.
Best Answer
Thank you for writing out the equation. Please note that the tension in the string can't be negative, because a string can't support negative tension (compression). It's the same as trying to push a wet noodle.
There are two ways of writing the force balance, depending on whether the upward direction is taken as positive or negative. Both ways give the exact same result for the tension.
Method 1: Upward direction is positive. Here, $$T-mg=ma$$where a is the upward acceleration of the mass. Since the acceleration of the mass is the same as the elevator, here, a = -1.65. So, $T=m(g-1.65)$
Method 2: Downward direction is positive. Here, $$mg-T=ma$$where a is the downward acceleration of the mass. Since the acceleration of the mass is the same as the elevator, here, a = + 1.65. So, $T=m(g-1.65)$
Either way you get the same answer.