It sounds like you have Wi-Fi Assist turned on, which does exactly what you describe. To quote what it says in my settings tab - "Automatically use mobile data when Wi-Fi connectivity is poor".
To turn it off, on your iPhone, go to:
Settings > Mobile Data > Scroll to the very bottom > Toggle off Wi-Fi Assist.
To turn it off, on your iPhone, go to:
Settings > Mobile Data > Scroll to the very bottom > Toggle off Wi-Fi Assist.