"sudo crontab -e" not updating /etc/hosts
When you issue a command via cron, you need to specify the whole path, so instead, you should use /usr/bin/sed.
There are a couple other issues you should consider:

cron is deprecated and this should be done using launchd instead

Why edit the file in place?  Simply save the original version of the hosts file  (i.e. /etc/hosts.orig) and create a new hosts file for when you want to block YouTube (i.e. /etc/hosts.nodistractions).  Just copy the appropriate file to /etc/hosts at the specified time interval.
For example, to unblock everything:
  cp /etc/hosts.orig /etc/hosts

To go into &quot;no distraction mode&quot;:
  cp /etc/hosts.nodistractions /etc/hosts



The benefit of using this method is you can easily edit the file to add more hosts as your distractions evolve and you won't have to modify the code. Running this as a LaunchDameon executes this as root so there's no permission issues to really worry about.  You won't have to contend with sudo or su or ensuring you're using the right user.
That said, there's an app called Focus ($20) that has a very rich feature set that will allow you to block not just websites, but apps as well.  There's a &quot;take a break&quot; function that will allow you to release the restrictions for a configurable amount of time allowing you to take a break or as you described, get something when needed.  The price point (IMO) is quite reasonable for what it provides.
Please note, I'm not affiliated with this app/company in any way nor do I personally use it. I just know of this product as a result of having to find a tool for parents of students - who were not focused on the task at hand - that gave them the ability to manage their distractions automatically; mainly due to location (parents at work, kids at home not doing homework).