How can in create a git submodule with two locations?

If you're working on Linux or MacOS, you can always use symlinks. Have submodule mysubmodule under main_project contain backend and frontend. And then create the two symlinks with the names you want. To your build environment, it'll look like the directory structure you want even if it's in one directory is the actual git submodule.

You can commit symlinks into a Git repo (and they'll work as long as you don't need to use this in Windows) so it's a one-time setup.

main_project
|
|-mysubmodule
|  -backend
|  -frontend
|
|-backend
|  - backend_submodule -> ../mysubmodule/backend
|  - other
|
|-frontend
   - frontend_subodule -> ../mysubmodule/frontend
   - other