Use regular expression matching to extract the number from the image file name, and read
to extract the new number from the corresponding text file. (Some details may need adjusting if I misunderstood your question, but the general approach will stay the same.)
for img in *.JPG; do
[[ $img =~ tramnummer([[:digit:]]+).JPG ]]
x=${BASH_REMATCH[1]}
read y < tramnummer$x.txt
mv tramnummer$x.JPG tramnummer$x-$y.JPG
done
In your existing code, you could use lines like
x=$(( x + 1 ))
y=$(< tramnummer$x.txt )
but the proposed solution is a little cleaner and more idiomatic.