Looks like Apple has this poorly documented. Basically, you shouldn't log in with your sandbox user from that screen. Log in when actually prompted by your test IAP.
I had this issue. I tried changing existing Sandbox tester account password and tried to login on device...but didn't worked.
Even iPhone device restart didn't worked [last option that most developer follows ;-) ]
I thought it takes time to update this newly created Sandbox testing on DB. So left the login option as it is on device
Now, after launching app that contains In App purchase. Press on button that is responsible for In App purchase. This will prompt for Apple credentials. Enter the Sandbox tester credentials here.
The top answer is correct, but if you're still having the issue:
Make sure that the app you're trying to log into is a development app installed with Xcode. You'll get the same error if your version was installed from the App Store.
(I got confused because I have 5 versions of almost the same app.)
For those who are still facing an issue, here is the solution:
From settings main screen, select "iTunes & App Store", as seen in the picture
now scroll to bottom and you will find your previous apple is still there, sign out of that, see picture for reference, and now when doing in app purchase, it will ask for both apple id and password, use your sandbox tester apple id and password there.