The hidden junction box is the key. Junction boxes are supposed to always be accessible, and this is one of the reasons why. But you have multiple issues here.
A dryer requires neutral. EVSE (a.k.a., "car charger") does not require neutral. Both currently require ground. But dryers used to not require ground. A dryer without ground (i.e., a proper 3-wire dryer circuit) can be grandfathered. But you don't have a proper 3-wire dryer circuit, and it can't be grandfathered anyway.
A proper 3-wire dryer circuit has hot, hot and neutral. A bare wire, with certain exceptions that absolutely do not apply here, is ground and not neutral. So you have a ground wire being used as neutral. That's strike one. It isn't to code and it isn't safe. That's separate from "combining neutral and ground" isn't safe - the bare wire, never designed to be neutral, ratchets up the "not safe" to another level.
In addition, even if this were OK as far as ground vs. neutral, this could not be grandfathered. Why? The dryer circuit is a proper 4-wire circuit, as you see in the breaker panel. Which means that either the improper 3-wire circuit used to go someplace else and was rerouted through the hidden junction box to a new circuit in the panel (the rerouting negating the grandfather clause) or it was originally in the hidden junction box location as a 4-wire circuit and was extended to a 3-wire circuit in a new location, which is a brand new circuit extension, so grandfathering never had a chance to apply. Either way, a 3-wire receptacle/circuit is simply not allowed for a dryer in your house. Period. That's strike two.
But wait, there's more! Do you see the difference between the 40A breaker and the 30A breakers? The 40A breaker is a double breaker. The 30A breaker is actually two single 30A breakers connected with a handle tie. A double breaker provides common shutoff (turn off one "half" for service and the both halves are guaranteed off) and common trip (if one side trips, both halves are guaranteed off). A handle tie provides common shutoff but does not provide common trip. For a lot of things that makes no difference. But for a dryer that uses neutral, it makes a huge difference. Essentially the heating element uses the two hots and the motor uses one hot + neutral. If the motor overloaded while the dryer was heating, it is possible to have the hot that feeds the motor trip and not the second hot. That would leave the dryer appearing to be dead (no controls lights or heating) but would still leave one hot wire live. That's strike three. A proper 30A double breaker doesn't cost very much - in fact normally very little, if anything, more than 2 single 30A breakers.
The interesting thing is that, assuming there are no other issues and the wire is sized correctly, 10 AWG, but even that I wouldn't assume without verification, this circuit can be used by dedicating it to EVSE. EVSE normally does not require neutral. It does require ground. But even that requires access to the hidden junction box to make sure (and fix it wrong) that the bare wire from this cable connects to ground only and not to neutral. Neutral in that hidden box would then be capped for future use. But if you do that, you will need an entirely new circuit for the dryer. If you simply extend from the hidden box to the current dryer location with a proper /3 cable (black hot/red hot, white neutral/bare ground) and install a 4-wire 14-30 receptacle then you can use it as planned.
But step 1 absolutely must be to access the hidden junction box. Depending on the type of cabinet (especially the material used for the back, which could be anything from 1/4" cardboard to 1" solid wood) and how precisely you know the location of the box, your options are:
- Move the cabinet. Measure and mark a hole in the cabinet for access. Move the cabinet back.
- Measure based on expected location. Cut some small exploratory holes until you find the junction box. Cut an access hole.
- Abandon the existing wires altogether and run a new /3 cable from the breaker panel to the dryer location.
There are a couple of other big considerations. This panel is full. It may be possible to add more half-size breakers. It is also possible, based on the other problems, that the panel is already more than full. The only way to tell is to check the instructions, which is usually on a label inside the panel door.
You may also have total load issues. Sharing the EVSE and dryer avoids making thing worse. But it is quite possible that either this panel or the main panel (I am assuming this is not the main panel based on lack of a main breaker, among other things) is oversubscribed. Not number of breakers (well, maybe that too...) but total power used. The way to do that is with a load calculation, which adds up various fixed loads, standard factors based on the size of the house, etc. and tells you how much power you need to provision to feed that panel properly. With so many half-size breakers, I am a bit concerned that a lot has been added without considering the feed to this subpanel or possibly even the utility feed to the main panel.
Based on a comment, this subpanel is the effective main panel for the house - i.e., almost every circuit comes from this panel, which is fed by a 100A breaker in a meter main that also houses solar, surge protector, HVAC, etc. Based on that, my real recommendation is:
- Add a new subpanel. I recommend a large panel (at least 30 spaces) and a main panel (just remove the neutral/ground bond and a ground bar if needed) can make a lot of sense due to the way these things are priced. Feed it with a 100A-ish (90A may make sense, depending on wire costs) breaker from the main panel, connected with appropriate aluminum wires or cable.
- Add a 30A double-breaker to the new subpanel for the dryer. Run /3 cable (hot/hot/neutral/ground) to the dryer location and install a NEMA 14-30 receptacle. Replace the dryer cord/plug with NEMA 14-30 and remove the dryer neutral/ground bond. You may need to put in a GFCI breaker, depending on local NEC version and local modifications. If so, that's the way it is. You can't grandfather the old stuff anyway.
- Add a 30A double-breaker to the new subpanel for the EVSE. Run /2 cable (hot/hot/ground) to the EVSE location. Install a hardwired EVSE. That avoids the GFCI requirement and is better anyway for a bunch of reasons.
- You can gradually add circuits as needed and/or move circuits from the existing subpanel.
- Abandon the old handle-tied 30A breakers and the wires attached to them. That avoids having to track down the hidden junction box. The spaces freed up can be used for other circuits. (Actually, if you don't have anything to put in there, leave the breakers in place so you don't have a hole in the front cover. But disconnect the wires.)