Short Answer
To answer your question: some schools specify bags students use, while others don't; it varies.
Long Answer
Like uniforms, bags are also specified by schools, which means the level of strictness varies from school to school. Some schools allow students to bring whatever bag they choose, while others will require students to buy from a specified maker, so that all bags have the school emblem.
While the hand-carried bags often seen in anime were once the main type of bag, most schools today use a 2-way or 3-way bag, that allows for multiple ways of carrying: by hand, diagonally over one shoulder, or on the the back. Also note that some schools use different colors for male and female students.
It should also be noted that the "backpacks" you are mentioning in Yuru Yuri and Nichijou are not backpacks in the broad sense (which would be リュックサック (rucksack) in Japanese), but ランドセル "randoseru" or "ransel", which are backpacks specifically for elementary school students. Wearing one above that age would definitely look odd to the a Japanese person.
Even when use is permitted, backpacks aren't always the first choice. While backpacks hold a lot, spread the weight between the shoulders, and allow for free use of both hands, they also have demerits, such as having to remove the backpack to access it, being unwieldy in tight spaces like trains, and making the back sweaty, especially in the summer.
Because this school-specified bag rule is common knowledge to the average Japanese viewer, any explanation is omitted in the work. So when an average viewer sees that everyone has the same bag, he/she would automatically assume that the school in this anime specifies the bag to use, and when another anime has different bags, then he/she would automatically assume this anime's school has no such regulation.
Wikipedia reference
Bag maker reference