The medicines which were prescribed to you are controlled medicines which cannot be purchased without a prescription. There is a reason for it - because they affect your brain. It's not recommended to play with the brain just for weight gain. There can be other repercussions.
To answer your questions -
No, it is not ok .
Yes, there are a lot of problems .
Please donot use the medicine again
Next Steps
There are other ways to gain weight , do try some of those