In foo the T in argument typename set<T>::iterator is a non-deduced contexts:
...the types, templates, and non-type values that are used to compose P do not participate in template argument deduction, but instead use the template arguments that were either deduced elsewhere or explicitly specified. If a template parameter is used only in non-deduced contexts and is not explicitly specified, template argument deduction fails.
The T is used in this non-deduced contexts and does not explicitly specify in foo what type it should deduce to, the compiler can not deuce the type; hence the error!
That means, if you explicitly mention what T in foo, it will compile as mentioned in the quote.
foo<int>(aSet.begin()); // compiles!
or better, provide the iterator as template parameter
template <typename Iterator> 
void foo(Iterator it1)
If you want to restrict the Iterator only for std::set<T>::iterator, you can SFINAE function. Here is an example code.
#include <type_traits> // std::enable_if, std::is_same
#include <iterator>    // std::iterator_traits
template<typename Iterator>
inline constexpr bool is_std_set_iterator = 
std::is_same_v<Iterator, typename std::set<typename std::iterator_traits<Iterator>::value_type>::iterator> ||
std::is_same_v<Iterator, typename std::set<typename std::iterator_traits<Iterator>::value_type>::const_iterator>;
template <typename Iterator>
auto foo(Iterator it1) -> std::enable_if_t<is_std_set_iterator<Iterator>, void>
{
    // do something
}
On the other hand, in bar the compiler already deduced the first function argument to std::set<int>& aSet and sees the typename std::set<T>::iterator, which it can deduce to typename std::set<int>::iterator, because T was already deduced to int in the previous function argument. Hence, it works!
As a side note, see the followings: