Why does the insulin taken from pig when injected into humans causes allergy but not the insulin taken from bacteria?
Proteins and peptides vary across species, even if we give them the same name. Some are very homologous among even distantly related organisms, others differ even within a genus. Of course there are also variations across individuals of the same species.

Insulin from pigs and horses is pig or horse insulin. It differs slightly from human insulin because the genes that encode insulin in pigs and horses are slightly different than the genes that encode insulin in humans. 

We inserted the genes responsible for producing insulin in humans into bacteria, so the insulin produced by recombinant bacteria is actually human insulin. That's why it doesn't produce an immune response.

There is also the issue of isolation and purification, and it is easier to produce very pure insulin free of other contaminants from recombinant sources than from animal sources.

That's the idea, anyways. Many humans tolerate porcine insulin just fine, and it isn't necessarily clear that human insulin is actually better (for example, this study).