You have to use following code to change animation blueprint. This function also changes animation mode to the BlueprintAnimated
SkeletalMeshComponent->SetAnimInstanceClass(AnimBlueprint->GeneratedClass);
Full code to change both skeleton and anim BP (taken from the actor factory)
// Term Component
NewSMActor->GetSkeletalMeshComponent()->UnregisterComponent();
// Change properties
NewSMActor->GetSkeletalMeshComponent()->SkeletalMesh = SkeletalMesh;
if (NewSMActor->GetWorld()->IsGameWorld())
{
NewSMActor->ReplicatedMesh = SkeletalMesh;
}
// Init Component
NewSMActor->GetSkeletalMeshComponent()->RegisterComponent();
if( AnimBlueprint )
{
NewSMActor->GetSkeletalMeshComponent()->SetAnimInstanceClass(AnimBlueprint->GeneratedClass);
}