You just render to the framebuffer, but instead of calling eglSwapBuffers to make the rendered image visible you call glCopyTexImage2D to copy the contents of the framebuffer to a texture.
This approach works everywhere, but it might require a copy operation, and you’re limited to the size of your current framebuffer.
Using an EGL pbuffer surface
You create a texture bindable pbuffer with eglCreatePbufferSurface. Then you make it the current draw surface of the context with eglMakeCurrent and render. When you’re finished you restore the previous draw surface and bind the pbuffer to a texture object using eglBindTexImage. Don’t forget to call eglReleaseTexImage when you’re finished.
Unfortunately some platforms don’t support pbuffer surfaces.
Instead of glCopyTexImage2D, you should use glCopyTexSubImage2D because the former allocates a texture and then does the copy and the later will just do a copy.