Short history lesson. Back when I was growing up, there was no label for YA or middle grade. You started with children's books, and then at some point you, your parent, or perhaps a librarian knew you were ready for the adult collection. "Ready" didn't always mean "emotionally mature" - it might be because that's where all the good fantasy/science fiction was shelved or it might be because you had already devoured all the books in the children's collection and your parent/librarian was tired of hand-picking books from the adult collection. (Interlibrary loan was only for adults back then.) Publishers did have some authors who wrote 'juvenile' (I do remember the Heinlein Juveniles were a thing at one point) and those would be shelved in the children's collection. Sometimes.
YA emerged as a label in the mid-70s (some will say 1950s or 1960s, but not where I was) and at that point it was thought to cover ages 10 through 18. Middle grade as an age range for books started about the time midde schools/junior highs became the fashion in the US - around the late 80s in some areas, early 1990s in others. Why and how have some classics have been relabeled as YA even though the term never existed when the book was written? It's all about the protagonist.
In panel discussions, several points have been repeated over and over. Age of the protagonist is one factor in the split between MG and YA. Middle grade has the protagonist aged between eight to twelve years old. In YA, the protagonist is older, usually thirteen and up. New Adult is a new term for the college-aged protagonist, which up to now was covered (sometimes) under YA. Classics - those books published before these terms came into use - often are relabeled YA if the protagonist fits in that age range, even if the main character is actually an adult reflecting on their childhood/young adulthood (Jane Eyre and To Kill A Mockingbird). Tamora Pierce's Circle series starts with her young mages around 10 years old. That was considered YA when the series first appeared, so her books might be considered MG by some and YA by others.
Middle grade readers have gatekeepers - parents and librarians who evaluate the books before purchase. So panelists often agree that swearing and sex is a dividing line between middle grade and young adult, no matter the age of the protagonist. Violence isn't always an issue with some gatekeepers.
Other dividing points (and there are always exceptions): middle grade covers external situations and adventures while YA is more introspective. Middle grade is more optimistic, while YA can be more edgy with uncertain endings. Middle grade focuses more on friends and family, while YA focuses on society. Before Harry Potter, middle grade books had a low word count, but that's not always true now.
Some other websites and blogs that discuss the definitions and distinctions:
How does the proposal for a Hugo for Best YA stand? There was supposedly a committee set up at the last Worldcon to look into it. There is still a Facebook group for the YA Hugo Proposal, but it's been quiet since 2014, and with the latest uproar about the 2015 Hugo nominations I'm not sure if there will even be any discussion about the topic at the business meeting at this year's Worldcon. We shall see.
What do you think are the differences between middle grade and young adult?