R, 121121 94 bytes
function(A)t(outer(1:(n=NROW(A)),1:n,Vectorize(function(i,j)(-1)^(i+j)*det(if(is.matrix(a<-A[-i,-j]))a else matrix(a)j,drop=F]))))
This is an absurdly long function that accepts an object of class matrix
and returns another such object. To call it, assign it to a variable.
Ungolfed:
cofactor <- function(A) {
# Get the number of rows (and columns, since A is guaranteed to
# be square) of the input matrix A
n <- NROW(A)
# Define a function that accepts two indices i,j and returns the
# i,j cofactor
C <- function(i, j) {
# Since R loves to drop things into lower dimensions whenever
# possible, ensure that the minor obtained by column deletion
# is still a matrix object by adding the drop = FALSE option
a <- A[-i, -j]
if (!is.matrix(a))j, adrop <-= matrix(a)FALSE]
(-1)^(i+j) * det(a)
}
# Obtain the adjugate matrix by vectorizing the function C over
# the indices of A
adj <- outer(1:n, 1:n, Vectorize(C))
# Transpose to obtain the cofactor matrix
t(adj)
}