At one of these two moments, depending on where your car is:
You walk first and take the shuttle when you finish, from El Chorro back to your car. The most common option.
You take the shuttle before walking up to the north access, and the route itself brings you back to your starting point.
The full car plan, including the €2 parking, is at where to park and how to get back to your car.
Because the official website gives two different time ranges on two different pages: its FAQ says one thing and its how-to-get-there page another. Publishing either one here would be gambling with your afternoon. The honest advice fits in one sentence: ask for the last bus time at the entrance itself, on the day, before you start walking. Thirty seconds that save you the one genuinely bad surprise of this visit.
The public transport with its own station at the Caminito is the train: the «El Chorro-Caminito del Rey» station is at the south end, and from there the shuttle takes you up to the north access. Train times change by season: check them at renfe.com.
And if what you want is a bus that takes you from Málaga and brings you back, that exists under another name: the full-day trip with transport and ticket included (★ 8.9, 2,200+ reviews, from €63.65). It solves the bus, the ticket and the car problem in one go.
More logistics: how to get there (car, train and accesses) · tickets and what to do when sold out.