but when I run the exact same command using another user ID [user2] the control does not return to the command prompt and the command looks like it froze.
You will find your life much easier of you stop using ssh with passwords as you are doing and move to password-less ssh using public-private key pairs.
There are 100s of tutorials on how to set this up in the net, here is one of those 100s of examples:
I can suggest how you can resolve the problem, because you usually have the same problem: you build some complex, interdepent, overly complicated thing and expect it to work. How about building one small thing, test it, building the next-bigger thing, test again, and so on, until you are finished. Each time you add something and it doesn't work any more you would know exactly where to look for, no?
So let us start:
[user2@server1 ~]$ ssh user1@server2
Does this work? Do you get a prompt on the remote server? Only if "yes", proceed - otherwise you have a problem with the connection. What it may be i don't know, but i would start with a ping to see if the server is reachable, etc..
do? sshpass uses a tty to trick ssh into believing the password was entered at command line. Chances are that this tty is somehow not there, taken away, whatever. It also might be that user2 has a different environment and some PATH or alias or privilege to access a certain command (or some dozens of other similar differences) is the culprit. Do you still get the command prompt with this?
By now you should know how to continue: add one step at a time and test. Good luck.
Finally, to emphasize what Neo has said, here is a quote from the man page of sshpass :
You have been told this several times in earlier threads and, honestly, i don't understand why you insist on using the "least best" (or, in other words: worst) practice, even in the words of the people who have written the tool you are using.
It is simply amazing to me why people love to build complicated, buggy, difficult to mantain, insecure solutions to problems which can be solved with simple, easy to maintain, more secure solutions.
Why?
Job security?
Having fun learning on the job getting paid by others?
I can assure you that if these guys were the owners of this IT and they were not getting paid to implement these overtly complex, buggy, hard to maintain, insecure solutions they would NOT do it.
Honestly, I keep seeing this more and more, especially from "certain countries" where the guys just seem to want to implement these overly complex, buggy, hard to maintain, and less secure solutions when, if they would just listen to us (people with many, many decades of coding and day to day sys admin experience, who likes simple, secure, easy to maintain, not buggy solutions), then their IT life would be a lot easier (and the questions here would be more practical).
I repeat....
Do not user sshpass. Use shared public-keys without passwords. It is more secure, less complex, easier to maintain and less buggy. I know. I do this every day on real systems!