How to detect /category and /tag base pages?

There is no good way to do this, but it can be done in a way. When you visit /category/ it serves it as though you are visiting a page called category. You can look for this like:

global $wp_query;
if ($wp_query->query_vars['pagename'] == "category")
{
  // This is base category
}
else if ($wp_query->query_vars['pagename'] == "tag")
{
// this is tag base
}

But this should never be done. It is basically a junk query; a 404, and will send a 404 response code, so you will need to look at sending another response code. For that reason (if you decide to use it) this code should go in header.php although it could go high in 404.php (before any output).