There are pros and cons to every schedule you can think of. Here are some general principles that people tend to follow (some are contradictory and I will point these out below):
1) Medicine before surgery. Important for the aspiring surgeons out there because you really want to shine on surgery and the surgery shelf is quite difficult. A lot of the surgery shelf is about managing medical problems for which the final treatment option is surgery. They do this because surgeons and to a lesser extent everybody else need to know the indications for surgery. It's pointless to test you on surgical techniques and approaches because that's not relevant to non-surgeon doctors. So they test you on whether you know when surgery would be indicated for common conditions and if surgery is not indicated, what the next treatment should be. I like to think of this as a treatment ladder - conservative -> medical therapy -> surgical treatment.
2) Medicine near the end of the year. This helps you shine on medicine which, along with surgery, is one of the most important rotations you will do in medical school. Having it near the end allows you to capitalize on all your prior experience. While content from psych or neurology may be less relevant to medicine (or at least make up only a small part of it), you would be surprised at how much the day-to-day knowledge you get from just being on clerkships builds up. If you've done a lot of inpatient rotations already and know how the hospital generally runs, it really helps you during medicine because you don't have to learn those things and can focus on the breadth of things there are to learn for medicine. Incidentally, this also helps you for Step 2 CK because medicine makes up the lion's share of questions on there so studying for the medicine shelf is the closest you'll get to studying for CK on clerkships. This material will then be fresh in your mind as you enter dedicated period, thus allowing you to condense your time and start off stronger.
3) Medicine early in the year. Others advocate for doing medicine early because it really sets the pace for all your subsequent rotations. You learn a ton on medicine that is directly relevant to clerkships like family medicine, neurology, etc. It's very helpful to be able to sit down, look through a patient's hospital meds, and understand exactly what it is, why they're getting what they're getting, and knowing how much room you have to go with the doses. The specialties are all interconnected and medicine is the centerpiece. Having medicine under your belt will help you perform well on those other rotations in this way.